Skip to content

Instantly share code, notes, and snippets.

@vsavkin
Created July 21, 2017 14:26
Show Gist options
  • Select an option

  • Save vsavkin/0a81482f7758d6829c49df96b8e538a2 to your computer and use it in GitHub Desktop.

Select an option

Save vsavkin/0a81482f7758d6829c49df96b8e538a2 to your computer and use it in GitHub Desktop.
import { MovieShowingsComponent } from './movie-showings.component';
import { cold, getTestScheduler } from 'jasmine-marbles';
describe('MovieShowingsComponent', () => {
it('should not have a race condition', () => {
const backend = jasmine.createSpyObj('backend', ['getShowings']);
const cmp = new MovieShowingsComponent(backend);
backend.getShowings.and.returnValue(cold('--x|', {x: ['10am']}));
cmp.selectMovie('After the Storm');
backend.getShowings.and.returnValue(cold('-y|', {y: ['11am']}));
cmp.selectMovie('Paterson');
// this will flush all observables
getTestScheduler().flush();
expect(cmp.movieTitle).toEqual('Paterson');
expect(cmp.showings).toEqual(['11am']); // This will fail because showings is ['10am'].
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment