"You created a second Pretender instance while there was already one running"

See original GitHub issue

I started getting this error today with ember-cli-mirage@0.2.2, and I’m fairly certain it has to do with Pretender 1.4.0 (that has a Notify on second Pretender fix) that was released today.

beforeEach failed on visiting /myroute/foo: You created a second Pretender instance while there
was already one running. Running two Pretender servers at once will lead to unexpected
results!Please call .shutdown() on your instances when you no longer need them to respond.

This was in my acceptance test. I have failures in my integration tests as well, which look like:

Promise rejected before it renders: Assertion Failed: You cannot use the same root element
(#ember-testing) multiple times in an Ember.Application

So what is the appropriate way to shutdown the Mirage server? I currently have this in my acceptance tests:

afterEach() {
  Ember.run(application, 'destroy');
  server.shutdown();
}

Do I need something similar in my integration tests?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:19
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
mdarmetkocommented, Jan 10, 2017

I’m using mostly default generated tests with ember 2.10 and was having this issue. Resolved it by adding if(server !== undefined) { server.shutdown(); } to beforeEach and afterEach in each acceptance test file. As in,

module('Acceptance: Metro', {
  beforeEach: function() {
    if(server !== undefined) { server.shutdown(); }
    application = startApp();
    originalConfirm = window.confirm;
    window.confirm = function() {
      confirmCalledWith = [].slice.call(arguments);
      return true;
    };
  },
  afterEach: function() {
    Ember.run(application, 'destroy');
    window.confirm = originalConfirm;
    confirmCalledWith = null;
    if(server !== undefined) { server.shutdown(); }
  }
});

Hope this helps someone else having the same problem.

6reactions
netescommented, Oct 13, 2016

Update: It seems that updating module-for-acceptance.js to the newest version (from Ember CLI 2.8) and adding this snippet to integration tests which use Mirage:

    afterEach() {
      server.shutdown();
    },

does the job - everything is fine then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

You created a second Pretender instance while there was ...
Running two Pretender servers at once will lead to unexpected results!Please call .shutdown() on your instances when you no longer need them to ......
Read more >
ember-cli-mirage in legacy app - Stack Overflow
You created a second Pretender instance while there was already one running. Running two Pretender servers at once will lead to unexpected ...
Read more >
Tutorial: Part 9 – Testing • Mirage JS
Jest should start a watcher that will re-run your tests every time you make ... You created a second Pretender instance while there...
Read more >
You created a second Pretender instance while there was ...
"You created a second Pretender instance while there was already one running" ... I started getting this error today with ember-cli-mirage@0.2.2 , ...
Read more >
Mocking your JSON API with Ember CLI Mirage - Culttt
Last week we went from static HTML to calling a property on the controller to retrieve data for an Ember template.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found