Controller instance refresh after test


#1

Hi,
So below I have my two tests but the last one is always failing because in the last one the fake is the same as the fake I created in my first mock. So my assumption is that the controller is still the same instance. How do I make sure I have a fresh instance of the controller for every test? Or is my test strategy wrong?

test('we can get a single movie', async ({assert, client}) => {
  const getMovieById = sinon.fake.returns('lol');
  ioc.fake('App/Services/PopcorntimeService', () => {
    return {
      getMovieById
    }
  })

  const response = await client.get('/movie/1').end()

  response.assertStatus(200)
  response.assertText('lol')

  assert.isTrue(getMovieById.called)
  assert.equal(getMovieById.args[0][0], '1')
  ioc.restore('App/Services/PopcorntimeService')
})

test('we can get a page with movies', async ({assert, client}) => {
  const getMovies = sinon.fake.returns('lol');
  ioc.fake('App/Services/PopcorntimeService', () => {
    return {
      getMovies
    }
  })

  const response = await client.get('/movies/1').end()
  // this fails because the service in my controller is still the fake in the first test and that 
  // doesn't contain the getMovies method but rather the getMovieById
  response.assertStatus(200)

  assert.isTrue(getMovies.called)
  assert.equal(getMovies.args[0][0], '1')
  ioc.restore('App/Services/PopcorntimeService')
})


#2

Might help to do something different instead of sinon.fake.returns('lol') each time.


#3

Obviously, and certainly not helping to make my point. But it’s not related to my issue :stuck_out_tongue: