【发布时间】:2017-09-16 22:13:45
【问题描述】:
documentation for Sails 0.12.11 解释了如何使用 Mocha 框架设置测试。我想使用 Jest 来做到这一点。
我尝试对bootstrap.test.js 使用相同的代码,但将before 替换为beforeAll,并将after 替换为afterAll;将this.timeout(5000) 替换为jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000。因为 Jest 期望文件中至少有一个测试,所以我在那里做了一个虚拟测试以确保它没有抱怨。
然后,在另一个文件 (some.test.js) 中,我尝试引用我创建的虚拟服务,以查看是否可以正常工作。使用 Mocha,任何 Sails 服务都应该默认可用,无需任何 require 语句。
it('should call the dummy service fine', () => {
expect(DummyService.doSomething()).toBe('ok');
});
在使用jest tests/* 运行测试时,我遇到了以下日志:
此外,虚拟服务测试失败,因为它说它没有定义。
FAIL tests/some.test.js
● should call the dummy service fine
ReferenceError: DummyService is not defined
【问题讨论】: