-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Symbol.iterator): correctly handle case where Symbol constructor …
…itself is not defined
- Loading branch information
Showing
2 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import { root } from '../../src/internal/util/root'; | ||
import { getSymbolIterator } from '../../src/internal/symbol/iterator'; | ||
|
||
describe('iterator symbol', () => { | ||
it('should use the real Symbol.iterator', () => { | ||
const Symbol_iterator = getSymbolIterator(root); | ||
expect(Symbol_iterator).to.equal(Symbol.iterator); | ||
}); | ||
|
||
it('should use a fake @@iterator string as a symbol when it the real one does not exist', () => { | ||
sinon.spy(console, 'warn'); | ||
|
||
const Symbol_iterator = getSymbolIterator({ | ||
Symbol: (() => {}) as SymbolConstructor // tslint:disable-line:no-empty | ||
}); | ||
expect(Symbol_iterator).to.equal('@@iterator'); | ||
expect(console.warn).have.been.calledWithExactly('RxJS: Symbol.iterator does not exist, so things like from(iterable) won\'t work'); | ||
|
||
(console.warn as any).restore(); | ||
}); | ||
|
||
it('should use a fake @@iterator string as a symbol when Symbol is not even defined', () => { | ||
sinon.spy(console, 'warn'); | ||
|
||
const Symbol_iterator = getSymbolIterator({}); | ||
expect(Symbol_iterator).to.equal('@@iterator'); | ||
expect(console.warn).have.been.calledWithExactly("RxJS: Symbol.iterator does not exist, so things like from(iterable) won't work"); | ||
|
||
(console.warn as any).restore(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters