Skip to content

Leaking state in program scope #446

@MichalBryxi

Description

@MichalBryxi

Consider following service:

var cachedFoo = null;

export default Service.extend({
  fetchFoo(count) {
    if(!cachedFoo) {
      fetch(`./api/?results=${count}`).then(function(response) {
        cachedFoo = response;
      });
    }
  }

  getFoo() {
    return cachedFoo;
  }
});

This service will probably work as expected in the scope of running Ember code.

But if there are two tests calling this service with different value for count when calling fetchFoo, then calls to getFoo will always return the response of the first test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions