mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
47e061549f
Summary: I was looking at the coverage report of the JavaScript code in the `Libraries` folder, and found some of the modules and functions to be (partially) untested. I believe that adding tests to them would formally capture their behaviour and avoid future regressions. In this PR, I've added some unit tests for 3 utility components. Perhaps a more general question: Are these kinds of PRs appreciated? I'd be interested in submitting more of them in the future. Not applicable, since it only adds tests. Pull Request resolved: https://github.com/facebook/react-native/pull/23903 Differential Revision: D14477601 Pulled By: cpojer fbshipit-source-id: c0700c5b514cd0df983fecfd91c93fc2bd049f5d
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
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+react_native
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
describe('stringifySafe', () => {
|
|
const stringifySafe = require('stringifySafe');
|
|
|
|
it('stringifySafe stringifies undefined values', () => {
|
|
expect(stringifySafe(undefined)).toEqual('undefined');
|
|
});
|
|
|
|
it('stringifySafe stringifies null values', () => {
|
|
expect(stringifySafe(null)).toEqual('null');
|
|
});
|
|
|
|
it('stringifySafe stringifies string values', () => {
|
|
expect(stringifySafe('abc')).toEqual('"abc"');
|
|
});
|
|
|
|
it('stringifySafe stringifies function values', () => {
|
|
expect(stringifySafe(function() {})).toEqual('function () {}');
|
|
});
|
|
|
|
it('stringifySafe stringifies non-circular objects', () => {
|
|
expect(stringifySafe({a: 1})).toEqual('{"a":1}');
|
|
});
|
|
|
|
it('stringifySafe stringifies circular objects with toString', () => {
|
|
const arg = {};
|
|
arg.arg = arg;
|
|
const result = stringifySafe(arg);
|
|
expect(result).toEqual('[object Object]');
|
|
});
|
|
|
|
it('stringifySafe stringifies circular objects without toString', () => {
|
|
const arg = {};
|
|
arg.arg = arg;
|
|
arg.toString = undefined;
|
|
const result = stringifySafe(arg);
|
|
expect(result).toEqual('["object" failed to stringify]');
|
|
});
|
|
});
|