mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: This diff removes the `sinon` dependency from `metro` and `react-native-github`. It was only used in a handful of tests and having to learn and remember another mocking API just for these cases was not worth it IMO. While doing the migration, most of the things that `sinon` provides can be done with `jest` in a very similar (and user friendly) way. I've found, though, two small things that are more user friendly with `sinon`. I'm documenting them here because it may be worth adding them to jest: With `sinon`: ``` stub.throws(new Error('foo')); ``` With `jest`: ``` mock.mockImplementation(() => { throw new Error('foo'); }); ``` Taking into account that `jest` has a `mockRejectedValue` method for mocks (to return a rejected promise) I don't see any reason why it does not have a `mockThrowError` method. With `sinon`: ``` expect(mock1.calledBefore(mock2)).toBeTruthy(); ``` With `jest`: ``` expect(mock1.mock.invocationCallOrder[0]).toBeLessThan( mock2.mock.invocationCallOrder[0], ); ``` There's a community matcher that adds this matcher in `jest-extended`: https://github.com/jest-community/jest-extended#tohavebeencalledbefore, but we're not using `jest-extended` in `xplat/js`. Reviewed By: jeanlauliac Differential Revision: D10238331 fbshipit-source-id: 5441125b69596ad85bf8f56d203cfd20759bc358
35 lines
936 B
JavaScript
35 lines
936 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @emails oncall+javascript_foundation
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const getDependencyConfig = require('../getDependencyConfig');
|
|
|
|
describe('getDependencyConfig', () => {
|
|
it("should return an array of dependencies' rnpm config", () => {
|
|
const config = {
|
|
getDependencyConfig: jest.fn(),
|
|
};
|
|
|
|
expect(Array.isArray(getDependencyConfig(config, ['abcd']))).toBeTruthy();
|
|
expect(config.getDependencyConfig.mock.calls.length).toEqual(1);
|
|
});
|
|
|
|
it('should filter out invalid react-native projects', () => {
|
|
const config = {
|
|
getDependencyConfig: jest.fn().mockImplementation(() => {
|
|
throw new Error('Cannot require');
|
|
}),
|
|
};
|
|
|
|
expect(getDependencyConfig(config, ['abcd'])).toEqual([]);
|
|
});
|
|
});
|