|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import wrap from 'jest-snapshot-serializer-raw'; |
| 9 | +import {runTest} from '../__mocks__/testUtils'; |
| 10 | + |
| 11 | +test('addEventHandler registers a callback with events', () => { |
| 12 | + const {stdout} = runTest(` |
| 13 | + let called = false; |
| 14 | + const callback = () => called = true; |
| 15 | + addEventHandler(callback); |
| 16 | +
|
| 17 | + describe('describe', () => { |
| 18 | + test('receives events', () => { |
| 19 | + console.log('called', called); |
| 20 | + expect(called).toEqual(true); |
| 21 | + }) |
| 22 | + }); |
| 23 | + `); |
| 24 | + |
| 25 | + expect(wrap(stdout)).toMatchSnapshot(); |
| 26 | +}); |
| 27 | + |
| 28 | +test('removeEventHandler unregisters a callback from events', () => { |
| 29 | + const {stdout} = runTest(` |
| 30 | + let called = false; |
| 31 | + const callback = () => called = true; |
| 32 | + addEventHandler(callback); |
| 33 | + removeEventHandler(callback); |
| 34 | +
|
| 35 | + describe('describe', () => { |
| 36 | + test('does not receive events', () => { |
| 37 | + console.log('called', called); |
| 38 | + expect(called).toEqual(false); |
| 39 | + }) |
| 40 | + }); |
| 41 | + `); |
| 42 | + |
| 43 | + expect(wrap(stdout)).toMatchSnapshot(); |
| 44 | +}); |
0 commit comments