You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Deno中运行原有Jasmine测试并使用其expect断言?

在Deno中使用Jasmine的expect运行现有测试

你可以通过两种方式在Deno中复用原有的Jasmine断言逻辑:

方法一:基于npm:jasmine-core初始化环境

jasmine-core的expect并非顶层导出,需要先创建并初始化Jasmine运行环境,再从环境实例中获取expect:

import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";
import Jasmine from "npm:jasmine-core";

// 初始化Jasmine运行环境
const jasmineEnv = Jasmine.createEnv();
jasmineEnv.configure({});
const { expect } = jasmineEnv;

describe('Preparing a game', () => {
  it('should be created', () => {
    expect(new Object()).toBeTruthy();
  });
});

方法二:使用npm:jasmine包(更简洁)

直接引入完整的jasmine包,它会自动处理环境初始化并直接导出expect:

import { describe, it } from "https://deno.land/std@0.178.0/testing/bdd.ts";
import { expect } from "npm:jasmine";

describe('Preparing a game', () => {
  it('should be created', () => {
    expect(new Object()).toBeTruthy();
  });
});

运行测试时执行deno test命令即可,两种方式都能让你先在Deno中跑通原有测试,后续再逐步迁移到Deno标准断言库。

内容的提问来源于stack exchange,提问作者Tyler Mumford

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 15:02:23