I have a Jasmine test file from an Angular project, and I'd like to convert it to use Deno's testing functions. But first, I want to have Deno run the tests as-is, using Jasmine's expect
and matchers.
Here's a minimal example of what I thought would work with deno test
:
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";
import { expect } from 'npm:jasmine-core';
describe('Preparing a game', () => {
it('should be created', () => {
expect(new Object()).toBeTruthy()
})
})
But this fails because 'npm:jasmine-core' does not provide an export named 'expect'
. Without that import line, of course, expect
is not defined.
(I intend to switch to Deno's standard asserts, but I first want to see if all the tests pass using the Jasmine assertions as currently written.)
Is there a way to run these tests with Jasmine's expect
?
You can use a substitute module — for example the one at https://deno.land/x/expect
— which passes the test in your question details.
test.ts
:
import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";
import { expect } from "https://deno.land/x/expect@v0.3.0/expect.ts";
describe("Preparing a game", () => {
it("should be created", () => {
expect(new Object()).toBeTruthy();
});
});
In the terminal:
% deno --version
deno 1.31.1 (release, aarch64-apple-darwin)
v8 11.0.226.13
typescript 4.9.4
% deno test
running 1 test from ./test.ts
Preparing a game ...
should be created ... ok (4ms)
Preparing a game ... ok (9ms)
ok | 1 passed (1 step) | 0 failed (23ms)
but I first want to see if all the tests pass using the Jasmine assertions as currently written
Of course, if you have not shown what you actually intend to test, then success will depend on exactly which APIs your tests use from the expect
namespace compared to what is offered in the module that you import.