plain-observable
Version:
A simple implementation of observable pattern
39 lines (38 loc) • 1.16 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
describe('Subject', () => {
let source;
beforeEach(() => {
source = new index_1.Subject();
});
test('should add observer when calling register method', () => {
spyOn(source, 'register');
source.register({
update(value) {
console.log(value);
}
});
expect(source.register).toHaveBeenCalled();
});
test('should notify observers with the passed value', () => {
const value = 'notify';
source.register({
update(value) {
expect(value).toBe(value);
}
});
spyOn(source, 'notify');
source.notify(value);
expect(source.notify).toHaveBeenCalledWith(value);
});
test('should unregister observer', () => {
const unregister = source.register({
update(value) {
expect(value).toBe(value);
}
});
unregister();
expect(source.size).toBe(0);
});
});
;