Skip to content

test(promise): test for error object names instead of specific messages #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/PromiseTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function testInvalidThen(param) {
});
return Promise.resolve(undefined);
}), (function (e) {
var ret = e.RE_EXN_ID === Js_exn.$$Error ? e._1.message === "p.then is not a function" : false;
var ret = e.RE_EXN_ID === Js_exn.$$Error ? e._1.name === "TypeError" : false;
Test.run([
[
"PromiseTest.res",
Expand Down Expand Up @@ -111,7 +111,7 @@ function testInvalidThenResolve(param) {
});
return Promise.resolve(undefined);
}), (function (e) {
var ret = e.RE_EXN_ID === Js_exn.$$Error ? e._1.message === "p.then is not a function" : false;
var ret = e.RE_EXN_ID === Js_exn.$$Error ? e._1.name === "TypeError" : false;
Test.run([
[
"PromiseTest.res",
Expand Down Expand Up @@ -181,7 +181,7 @@ function testExternalPromiseThrow(param) {
return Core__Promise.$$catch(Curry._1(asyncParseFail, undefined).then(function (param) {
return Promise.resolve(undefined);
}), (function (e) {
var success = e.RE_EXN_ID === Js_exn.$$Error ? Caml_obj.equal(e._1.message, "Unexpected token . in JSON at position 1") : false;
var success = e.RE_EXN_ID === Js_exn.$$Error ? Caml_obj.equal(e._1.name, "SyntaxError") : false;
Test.run([
[
"PromiseTest.res",
Expand Down
6 changes: 3 additions & 3 deletions test/PromiseTest.res
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module ThenChaining = {
})
->catch(e => {
let ret = switch e {
| Exn.Error(m) => Exn.message(m) === Some("p.then is not a function")
| Exn.Error(m) => Exn.name(m) === Some("TypeError")
| _ => false
}
Test.run(__POS_OF__("then should have thrown an error"), ret, equal, true)
Expand Down Expand Up @@ -101,7 +101,7 @@ module ThenChaining = {
})
->catch(e => {
let ret = switch e {
| Exn.Error(m) => Exn.message(m) === Some("p.then is not a function")
| Exn.Error(m) => Exn.name(m) === Some("TypeError")
| _ => false
}
Test.run(__POS_OF__("then should have thrown an error"), ret, equal, true)
Expand Down Expand Up @@ -156,7 +156,7 @@ module Catching = {
->then(_ => resolve()) // Since our asyncParse will fail anyways, we convert to promise<unit> for our catch later
->catch(e => {
let success = switch e {
| Exn.Error(err) => Exn.message(err) == Some("Unexpected token . in JSON at position 1")
| Exn.Error(err) => Exn.name(err) == Some("SyntaxError")
| _ => false
}

Expand Down