Skip to content

Commit

Permalink
Signals: correctly return zero values (ampproject#23951)
Browse files Browse the repository at this point in the history
* Signals: correctly return zero values

* review fixes
  • Loading branch information
Dima Voytenko authored Aug 14, 2019
1 parent 7f86750 commit ff414a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class Signals {
* @return {number|!Error|null}
*/
get(name) {
return this.map_[name] || null;
const v = this.map_[name];
return v == null ? null : v;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions test/unit/utils/test-signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,18 @@ describes.sandboxed('Signals', {}, () => {
expect(signals.promiseMap_['sig']).to.be.undefined;
});
});

describes.sandboxed('Signals with zero for tests', {}, () => {
let signals;

beforeEach(() => {
sandbox.useFakeTimers();
signals = new Signals();
});

it('should register signal without promise', () => {
// The signal value is often 0 in tests due to the fake timer.
signals.signal('sig');
expect(signals.get('sig')).to.equal(0);
});
});

0 comments on commit ff414a1

Please sign in to comment.