如何在Deno中运行Jasmine测试?

huangapple go评论60阅读模式
英文:

How can I run Jasmine tests with Deno?

问题

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?

英文:

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?

答案1

得分: 1

你可以使用一个替代模块,例如 https://deno.land/x/expect 中的模块,这个模块可以通过你的问题详情中的测试。

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();
  });
});

在终端中:

% 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)

但首先,我想看看所有的测试是否通过,使用当前的Jasmine断言来写。

当然,如果你还没有展示你实际打算测试什么,那么成功与否将取决于你的测试从expect命名空间中使用哪些API,与你导入的模块提供了哪些API。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月1日 16:22:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601127.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定