ember-data-factory-guy: MockFindRecord.fails() does not capture preflighted requests

I’m trying to test the behaviour for a HTTP 404 response of the backend:

    describe('HTTP 404 from backend', function() {
      beforeEach(function() {
        broadcastMock.fails({status: 404, response: {errors: {status: '404', name: ["broadcast not found"]}}});
      });

      it('shows a 404 error page', function() {
        visit('/broadcast/' + broadcast.get('id'));

        return andThen(() => {
          expect(find('p').text()).to.have.string('We could not find that page');
        });
      });

Apparently that is not possible, because the .fails() does not capture the preflighted request and therefore I get an Error: The adapter operation was aborted and the route cannot reach the error event.

I believe this is a bug.

See the entire acceptance test here: https://github.com/roschaefer/rundfunk-mitbestimmen/commit/42feff029c96785328e8f839867da797773a909a

selection_086

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 34 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Oddly the example I showed was fine because the mock model that was returning was the same one returned by the mockFindRecord. In your case that was also the case ( I think ) BUT the big difference is: This test that passes is expecting the model to be found.

You were expecting a find to fail when that model was in the ember data store. That just did not sit well with ember data. That is why for a fail you should not use returns({model: myModel}).fails() just do .fails on the mock and stop there.

I am going to fix the docs to show that and even put a fails test in the acceptance tests as well If you can think of anything else to document, let me know

you are making one very small error I will post this again with your setup too, ( that is clue ) and give you 5 minutes to figure it out:

 beforeEach(function() {
     broadcastMock = mockFindRecord('broadcast');
     broadcast = make('broadcast', {  title: 'This is the title'  })
  });
 describe('HTTP 404 from backend', function() {
      it('shows a 404 error page', function() {
        broadcastMock.fails({status: 404, response: {errors: {status: '404', name: ["broadcast not found"]}}});

        visit('/broadcast/' + broadcast.get('id'));

        return andThen(() => {
          expect(find('p').text()).to.have.string('We could not find that page');
        });
      });

If after 5 mins you don’t get it I will give more clues 😃