Skip to content

Commit

Permalink
update tests dontMock -> doUnmock
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza committed Aug 13, 2024
1 parent 1cba7ab commit f127016
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
12 changes: 4 additions & 8 deletions test/tests/extras.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ describe(`Extra Tests`, () => {
describe(`Built Tests`, () => {
// see: https://github.com/LeDDGroup/typescript-transform-paths/issues/130
test(`Transformer works without ts-node being present`, () => {
vi.doMock(
"ts-node",
() => {
throw new ModuleNotFoundError("ts-node");
},
{ virtual: true },
);
vi.doMock("ts-node", () => {
throw new ModuleNotFoundError("ts-node");
});
try {
const program = createTsProgram({ tsInstance: ts, tsConfigFile }, config.builtTransformerPath);
const res = getEmitResultFromProgram(program);
expect(res[indexFile].js).toMatch(`var _identifier_1 = require("./id")`);
} finally {
vi.dontMock("ts-node");
vi.doUnmock("ts-node");
}
});

Expand Down
16 changes: 6 additions & 10 deletions test/tests/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,17 @@ describe(`Register script`, () => {

describe(`Register`, () => {
test(`Throws without ts-node`, () => {
vi.doMock(
"ts-node",
() => {
throw new ModuleNotFoundError("ts-node");
},
{ virtual: true },
);
vi.doMock("ts-node", () => {
throw new ModuleNotFoundError("ts-node");
});
expect(() => register()).toThrow(`Cannot resolve ts-node`);
vi.dontMock("ts-node");
vi.doUnmock("ts-node");
});

test(`Throws if can't register ts-node`, () => {
vi.doMock("ts-node", () => ({ register: () => {} }), { virtual: true });
vi.doMock("ts-node", () => ({ register: () => {} }));
expect(() => register()).toThrow(`Could not register ts-node instance!`);
vi.dontMock("ts-node");
vi.doUnmock("ts-node");
});

test(`No transformers in tsConfig exits quietly`, () => {
Expand Down

0 comments on commit f127016

Please sign in to comment.