如何在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
相关产品推荐
相关产品推荐

