Skip to content

Commit

Permalink
Add tests for error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Apr 3, 2021
1 parent 23e0bf1 commit f07223d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/babel-parser/test/error-codes.js
@@ -0,0 +1,21 @@
import { parse } from "../lib";

describe("error codes", function () {
it("raises an error with BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED and reasonCode", function () {
const code = `import "foo"`;
const { errors } = parse(code, {
errorRecovery: true,
sourceType: "script",
});
const error = errors[0];
expect(error.code).toBe("BABEL_PARSER_SOURCETYPE_MODULE_REQUIRED");
expect(error.reasonCode).toBe("ImportOutsideModule");
});
it("raises an error with BABEL_PARSER_SYNTAX_ERROR and reasonCode", function () {
const code = `a b`;
const { errors } = parse(code, { errorRecovery: true });
const error = errors[0];
expect(error.code).toBe("BABEL_PARSER_SYNTAX_ERROR");
expect(error.reasonCode).toBe("MissingSemicolon");
});
});

0 comments on commit f07223d

Please sign in to comment.