Download react-hook-form/src/__tests__/utils/createSubject.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/createSubject.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/createSubject.test.ts
-
curl -L -o createSubject.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/src/__tests__/utils/createSubject.test.ts
1.37 kB
| import createSubject from '../../utils/createSubject'; | |
| describe('createSubject', () => { | |
| it('should subscribe to all the correct observer', () => { | |
| const subject = createSubject(); | |
| const next = jest.fn(); | |
| subject.subscribe({ | |
| next, | |
| }); | |
| subject.subscribe({ | |
| next, | |
| }); | |
| expect(subject.observers.length).toBe(2); | |
| subject.next(2); | |
| expect(next).toBeCalledTimes(2); | |
| expect(next).toBeCalledWith(2); | |
| }); | |
| it('should unsubscribe observers', () => { | |
| const subject = createSubject(); | |
| const next1 = jest.fn(); | |
| const next2 = jest.fn(); | |
| const subscription = subject.subscribe({ | |
| next: next1, | |
| }); | |
| subject.subscribe({ | |
| next: next2, | |
| }); | |
| expect(subject.observers.length).toBe(2); | |
| subscription.unsubscribe(); | |
| expect(subject.observers.length).toBe(1); | |
| subject.next(2); | |
| expect(next1).not.toBeCalled(); | |
| expect(next2).toBeCalledWith(2); | |
| }); | |
| it('should unsubscribe all observers', () => { | |
| const subject = createSubject(); | |
| const next = jest.fn(); | |
| subject.subscribe({ | |
| next, | |
| }); | |
| subject.subscribe({ | |
| next, | |
| }); | |
| expect(subject.observers.length).toBe(2); | |
| subject.unsubscribe(); | |
| expect(subject.observers.length).toBe(0); | |
| subject.next(2); | |
| subject.next(2); | |
| expect(next).not.toBeCalled(); | |
| }); | |
| }); | |