Ember-cli:如何在开发和测试环境之间共享fixture?

Ember-cli: How to share fixtures between development and test environments?

我在使用 ember-cli 开发应用程序原型期间使用了 http-stubs。 我想要的是在测试环境中重用该存根,但由于看起来像 ember-cli 无法弄清楚如何在测试环境中使用夹具适配器。

有一个 PR 允许在测试期间使用 HTTP Mocks,这听起来像您所描述的,但确定这不是测试您的应用程序的好方法。

从讨论包括模拟在内的问题,this comment stated:

...We can to an agreement that mocks are useful for development but are an anti-pattern in testing. We decided that instead of spending time making mocks working in ember test --server we are going to show how to do proper mocking in testing using Pretender.

Stefan showed me an example of mocking with Pretender and the test code is much more readable than having mock server with responses hidden away in the ./server configuration. I'm going to spend some time this weekend looking at what can be scavenged from related PR...

原始问题中包含来自 stefanpenner 的关于如何设置伪装者进行测试的示例,可以在 here.

中找到

该示例中的示例测试如下所示:

test('searching', () => {
  server.get('/jobs', json(200, {
    jobs: [
      job({ title: 'UI Engineer'     }),
      job({ location: 'Palo Alto', title: 'UI Engineer'     }),
      job({ location: 'Palo Alto', title: 'Backend Engineer'}),
    ]
  }));
 
  server.get('/companies', json(200, {
    companies: []
  }));
 
  return visit('/').then(() => {
    equal(numberOfJobs(), 3, 'expected 3 jobs');
 
    fillIn($('#search-field'), 'UI').then(() => {
      equal(numberOfJobs(), 2, 'expected 2 jobs');
    });
 
    fillIn($('#search-field'), 'ASDFASDF').then(() => {
      equal(numberOfJobs(), 0, 'expected 0 jobs');
    });
 
    fillIn($('#search-field'), 'Palo alto').then(() => {
      equal(numberOfJobs(), 2, 'expected 2 jobs');
    });
 
    return fillIn($('#search-field'), '').then(() => {
      equal(numberOfJobs(), 3, 'expected 3 jobs');
    });
  });
});