Skip to content

Commit

Permalink
fix: remove broken toThrow* expects
Browse files Browse the repository at this point in the history
  • Loading branch information
glennsl committed Mar 14, 2021
1 parent 6b740c4 commit c30f05f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 142 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ Then build and run tests with `npm test`, start watchers for `bsb`and `jest` wit

## Changes

### 0.7

- [BREAKING] Actually removed `toThrowException`, `toThrowMessage` and `toThrowMessageRe` as they relied on assumptions about BuckleScript internals that no longer hold.

### 0.6
* Added `Expect.toContainEqual`
* Updated to Jest 26.5.2
* Upgraded bs-platform to 8.3.1
* Remvoed `toThrowException`, `toThrowMessage` and `toThrowMessageRe` as they relied on assumptions about BuckleScript internals that no longer hold.

### 0.5.1
* Added `Expect.toMatchInlineSnapshot`
Expand Down
174 changes: 54 additions & 120 deletions lib/js/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,89 +146,65 @@ function affirm(message) {
} else {
return expect(match$39.VAL).not.toThrow();
}
case /* ThrowsException */15 :
var match$40 = message._0;
if (match$40.NAME === "Just") {
var match$41 = match$40.VAL;
return expect(match$41[0]).toThrow(JSON.stringify(match$41[1]));
}
var match$42 = match$40.VAL;
return expect(match$42[0]).not.toThrow(JSON.stringify(match$42[1]));
case /* ThrowsMessage */16 :
var match$43 = message._0;
if (match$43.NAME === "Just") {
var match$44 = match$43.VAL;
return expect(match$44[0]).toThrow(match$44[1]);
}
var match$45 = match$43.VAL;
return expect(match$45[0]).not.toThrow(match$45[1]);
case /* ThrowsMessageRe */17 :
var match$46 = message._0;
if (match$46.NAME === "Just") {
var match$47 = match$46.VAL;
return expect(match$47[0]).toThrow(match$47[1]);
}
var match$48 = match$46.VAL;
return expect(match$48[0]).not.toThrow(match$48[1]);
case /* MatchInlineSnapshot */18 :
case /* MatchInlineSnapshot */15 :
return expect(message._0).toMatchInlineSnapshot(message._1);
case /* MatchSnapshot */19 :
case /* MatchSnapshot */16 :
return expect(message._0).toMatchSnapshot();
case /* MatchSnapshotName */20 :
case /* MatchSnapshotName */17 :
return expect(message._0).toMatchSnapshot(message._1);
case /* ThrowsMatchSnapshot */21 :
case /* ThrowsMatchSnapshot */18 :
return expect(message._0).toThrowErrorMatchingSnapshot();
case /* Defined */22 :
var match$49 = message._0;
if (match$49.NAME === "Just") {
return expect(match$49.VAL).toBeDefined();
case /* Defined */19 :
var match$40 = message._0;
if (match$40.NAME === "Just") {
return expect(match$40.VAL).toBeDefined();
} else {
return expect(match$49.VAL).not.toBeDefined();
return expect(match$40.VAL).not.toBeDefined();
}
case /* Falsy */23 :
var match$50 = message._0;
if (match$50.NAME === "Just") {
return expect(match$50.VAL).toBeFalsy();
case /* Falsy */20 :
var match$41 = message._0;
if (match$41.NAME === "Just") {
return expect(match$41.VAL).toBeFalsy();
} else {
return expect(match$50.VAL).not.toBeFalsy();
return expect(match$41.VAL).not.toBeFalsy();
}
case /* Null */24 :
var match$51 = message._0;
if (match$51.NAME === "Just") {
return expect(match$51.VAL).toBeNull();
case /* Null */21 :
var match$42 = message._0;
if (match$42.NAME === "Just") {
return expect(match$42.VAL).toBeNull();
} else {
return expect(match$51.VAL).not.toBeNull();
return expect(match$42.VAL).not.toBeNull();
}
case /* Truthy */25 :
var match$52 = message._0;
if (match$52.NAME === "Just") {
return expect(match$52.VAL).toBeTruthy();
case /* Truthy */22 :
var match$43 = message._0;
if (match$43.NAME === "Just") {
return expect(match$43.VAL).toBeTruthy();
} else {
return expect(match$52.VAL).not.toBeTruthy();
return expect(match$43.VAL).not.toBeTruthy();
}
case /* Undefined */26 :
var match$53 = message._0;
if (match$53.NAME === "Just") {
return expect(match$53.VAL).toBeUndefined();
case /* Undefined */23 :
var match$44 = message._0;
if (match$44.NAME === "Just") {
return expect(match$44.VAL).toBeUndefined();
} else {
return expect(match$53.VAL).not.toBeUndefined();
return expect(match$44.VAL).not.toBeUndefined();
}
case /* ObjectContains */27 :
var match$54 = message._0;
if (match$54.NAME === "Just") {
var match$55 = match$54.VAL;
return expect(match$55[0]).toEqual(objectContaining(match$55[1]));
case /* ObjectContains */24 :
var match$45 = message._0;
if (match$45.NAME === "Just") {
var match$46 = match$45.VAL;
return expect(match$46[0]).toEqual(objectContaining(match$46[1]));
}
var match$56 = match$54.VAL;
return expect(match$56[0]).not.toEqual(objectContaining(match$56[1]));
case /* ObjectMatch */28 :
var match$57 = message._0;
if (match$57.NAME === "Just") {
var match$58 = match$57.VAL;
return expect(match$58[0]).toMatchObject(match$58[1]);
var match$47 = match$45.VAL;
return expect(match$47[0]).not.toEqual(objectContaining(match$47[1]));
case /* ObjectMatch */25 :
var match$48 = message._0;
if (match$48.NAME === "Just") {
var match$49 = match$48.VAL;
return expect(match$49[0]).toMatchObject(match$49[1]);
}
var match$59 = match$57.VAL;
return expect(match$59[0]).not.toMatchObject(match$59[1]);
var match$50 = match$48.VAL;
return expect(match$50[0]).not.toMatchObject(match$50[1]);

}
}
Expand Down Expand Up @@ -628,7 +604,7 @@ function toMatch(s, p) {

function toMatchInlineSnapshot(inlineSnapshot, param) {
return {
TAG: /* MatchInlineSnapshot */18,
TAG: /* MatchInlineSnapshot */15,
_0: param.VAL,
_1: inlineSnapshot
};
Expand All @@ -648,14 +624,14 @@ function toMatchRe(re, p) {

function toMatchSnapshot(param) {
return {
TAG: /* MatchSnapshot */19,
TAG: /* MatchSnapshot */16,
_0: param.VAL
};
}

function toMatchSnapshotWithName(name, param) {
return {
TAG: /* MatchSnapshotName */20,
TAG: /* MatchSnapshotName */17,
_0: param.VAL,
_1: name
};
Expand All @@ -670,47 +646,11 @@ function toThrow(f) {

function toThrowErrorMatchingSnapshot(param) {
return {
TAG: /* ThrowsMatchSnapshot */21,
TAG: /* ThrowsMatchSnapshot */18,
_0: param.VAL
};
}

function toThrowException(e, p) {
return {
TAG: /* ThrowsException */15,
_0: mapMod((function (f) {
return [
f,
e
];
}), p)
};
}

function toThrowMessage(message, p) {
return {
TAG: /* ThrowsMessage */16,
_0: mapMod((function (f) {
return [
f,
message
];
}), p)
};
}

function toThrowMessageRe(re, p) {
return {
TAG: /* ThrowsMessageRe */17,
_0: mapMod((function (f) {
return [
f,
re
];
}), p)
};
}

function not_(param) {
return {
NAME: "Not",
Expand Down Expand Up @@ -784,52 +724,49 @@ var Expect = {
toMatchSnapshotWithName: toMatchSnapshotWithName,
toThrow: toThrow,
toThrowErrorMatchingSnapshot: toThrowErrorMatchingSnapshot,
toThrowException: toThrowException,
toThrowMessage: toThrowMessage,
toThrowMessageRe: toThrowMessageRe,
not_: not_,
not__: not_,
Operators: Operators
};

function toBeDefined(a) {
return {
TAG: /* Defined */22,
TAG: /* Defined */19,
_0: a
};
}

function toBeFalsy(a) {
return {
TAG: /* Falsy */23,
TAG: /* Falsy */20,
_0: a
};
}

function toBeNull(a) {
return {
TAG: /* Null */24,
TAG: /* Null */21,
_0: a
};
}

function toBeTruthy(a) {
return {
TAG: /* Truthy */25,
TAG: /* Truthy */22,
_0: a
};
}

function toBeUndefined(a) {
return {
TAG: /* Undefined */26,
TAG: /* Undefined */23,
_0: a
};
}

function toContainProperties(props, p) {
return {
TAG: /* ObjectContains */27,
TAG: /* ObjectContains */24,
_0: mapMod((function (a) {
return [
a,
Expand All @@ -841,7 +778,7 @@ function toContainProperties(props, p) {

function toMatchObject(b, p) {
return {
TAG: /* ObjectMatch */28,
TAG: /* ObjectMatch */25,
_0: mapMod((function (a) {
return [
a,
Expand Down Expand Up @@ -874,9 +811,6 @@ var ExpectJs = {
toMatchSnapshotWithName: toMatchSnapshotWithName,
toThrow: toThrow,
toThrowErrorMatchingSnapshot: toThrowErrorMatchingSnapshot,
toThrowException: toThrowException,
toThrowMessage: toThrowMessage,
toThrowMessageRe: toThrowMessageRe,
not_: not_,
not__: not_,
Operators: Operators,
Expand Down
18 changes: 0 additions & 18 deletions src/jest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ type assertion =
| StringMatch : (string * Js.Re.t) modifier -> assertion

| Throws : (unit -> _) modifier -> assertion
| ThrowsException : ((unit -> _) * exn) modifier -> assertion
| ThrowsMessage : ((unit -> _) * string) modifier -> assertion
| ThrowsMessageRe : ((unit -> _) * Js.Re.t) modifier -> assertion

| MatchInlineSnapshot : _ * string -> assertion
| MatchSnapshot : _ -> assertion
Expand Down Expand Up @@ -104,12 +101,6 @@ end = struct

| Throws `Just f -> (expect f) ## toThrow ()
| Throws `Not f -> (expect f) ## not ## toThrow ()
| ThrowsException `Just (f, e) -> (expect f) ## toThrow (Js.Json.stringifyAny e)
| ThrowsException `Not (f, e) -> (expect f) ## not ## toThrow (Js.Json.stringifyAny e)
| ThrowsMessage `Just (f, msg) -> (expect f) ## toThrow msg
| ThrowsMessage `Not (f, msg) -> (expect f) ## not ## toThrow msg
| ThrowsMessageRe `Just (f, re) -> (expect f) ## toThrow re
| ThrowsMessageRe `Not (f, re) -> (expect f) ## not ## toThrow re

| MatchInlineSnapshot (a, inlineSnapshot) -> (expect a) ## toMatchInlineSnapshot inlineSnapshot
| MatchSnapshot a -> (expect a) ## toMatchSnapshot ()
Expand Down Expand Up @@ -363,15 +354,6 @@ module Expect = struct
let toThrowErrorMatchingSnapshot (`Just f) =
ThrowsMatchSnapshot f

let toThrowException e p =
ThrowsException (mapMod (fun f -> (f, e)) p)

let toThrowMessage message p =
ThrowsMessage (mapMod (fun f -> (f, message)) p)

let toThrowMessageRe re p =
ThrowsMessageRe (mapMod (fun f -> (f, re)) p)

let not_ (`Just a) = `Not a
let not__ = not_ (* For Reason syntax compatibility. TODO: deprecate and remove *)

Expand Down
3 changes: 0 additions & 3 deletions src/jest.mli
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ module Expect : sig
val toMatchSnapshotWithName : string -> _ plainPartial -> assertion
val toThrow : [< (unit -> _) partial] -> assertion
val toThrowErrorMatchingSnapshot : (unit -> _) plainPartial -> assertion
val toThrowException : exn -> [< (unit -> _) partial] -> assertion
val toThrowMessage : string -> [< (unit -> _) partial] -> assertion
val toThrowMessageRe : Js.Re.t -> [< (unit -> _) partial] -> assertion

val not_ : 'a plainPartial -> 'a invertedPartial
val not__ : 'a plainPartial -> 'a invertedPartial
Expand Down

0 comments on commit c30f05f

Please sign in to comment.