在我的量角器e2e测试中,我想使用httpBackendMock
的模拟数据。但是我无法访问/将数据注入模拟模块。下面是我的咖啡代码。
describe 'my test page', ->
ptor = protractor.getInstance()
page = require('./pages/FooPage.js')
fooPage = new page()
data = require('./data/testdata.json').data
describe 'happy path', ->
beforeEach ->
httpBackendMock = ->
angular.module('httpBackendMock', ['ngMockE2E', 'fooApp.controllers']).run ($httpBackend) ->
mockData = data
当我运行测试时,行mockData = data
失败(抱怨data
未定义)。
据我所知,这是由于执行的不同背景所致
https://github.com/angular/protractor/issues/509
那么我如何在angular mock模块中指定模拟数据变量?我不想在测试中对数据进行硬编码。
答案 0 :(得分:3)
describe 'my test page', ->
page = require('./pages/FooPage.js')
httpBackend = require('http-backend-proxy')
fooPage = new page()
mockData = require('./data/testdata.json')
describe 'my test steps', ->
beforeEach ->
proxy = new httpBackend(browser)
proxy.onLoad.whenGET('/foo/v1/userinfo').respond(200, mockData)
proxy.onLoad.whenGET(/.*/).passThrough()
fooPage.get()
browser.driver.manage().window().maximize()
describe 'main page scenarios', ->
it 'scenario 1', ->
usual expect and toBe stuff