我是使用requirejs和using the requirejs map configuration测试模块的jasmine单元,以提供模拟的依赖项。但是,这仅适用于第一次测试运行,之后模块已经加载并且检索了缓存版本,因此其他测试最终不会加载他们的模拟但返回第一次测试的模拟。
假设我有这个
define 'directory', ['dataService'], (ds) ->
ds.doStuff()
configureStub = (name, fn) ->
define name, fn
require.config
map:
directory:
dataService: name
describe 'test fixture 1', ->
beforeEach ->
configureStub 'mockDataService1', -> doStuff: -> console.log "doing things"
it "uses the first mock service" -> ...
describe 'test fixture 2', ->
beforeEach ->
configureStub 'mockDataService2', -> doStuff: -> console.log "doing other things"
it "uses the second mock service" -> ...
由于directory
和dataService
都已缓存且测试之间的页面未刷新,因此mockDataService2
永远不会被加载,它始终为mockDataService1
!
有没有办法在我的测试设置中手动清除requirejs缓存中的directory
和dataService
?
答案 0 :(得分:0)
我觉得这仍然是一个值得回答的有效问题,但对于完全与我相同情况的人,我设法用squire.js和jasmine的组合来解决问题。 AJAX。