Skip to content

Commit

Permalink
adding jest test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fabOnReact committed Feb 7, 2022
1 parent b3a90cd commit 94a6a7f
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Libraries/Components/Switch/__tests__/Switch-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* 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
* @flow strict-local
*/

import * as React from 'react';

import Switch from '../Switch';
import View from '../../View/View';
import {expectRendersMatchingSnapshot} from '../../../Utilities/ReactNativeTestTools';

describe('<Switch />', () => {
it('should render as expected', () => {
expectRendersMatchingSnapshot(
'Switch',
() => (
<Switch>
<View />
</Switch>
),
() => {
jest.dontMock('../Switch');
},
);
});
});

describe('<Switch disabled={true} />', () => {
it('should be disabled when disabled is true', () => {
expectRendersMatchingSnapshot(
'Switch',
() => (
<Switch disabled={true}>
<View />
</Switch>
),
() => {
jest.dontMock('../Switch');
},
);
});
});

describe('<Switch disabled={true} accessibilityState={{}} />', () => {
it('should be disabled when disabled is true and accessibilityState is empty', () => {
expectRendersMatchingSnapshot(
'Switch',
() => (
<Switch disabled={true} accessibilityState={{}}>
<View />
</Switch>
),
() => {
jest.dontMock('../Switch');
},
);
});
});

describe('<Switch disabled={true} accessibilityState={{checked: true}} />', () => {
it('should keep accessibilityState when disabled is true', () => {
expectRendersMatchingSnapshot(
'Switch',
() => (
<Switch disabled={true} accessibilityState={{checked: true}}>
<View />
</Switch>
),
() => {
jest.dontMock('../Switch');
},
);
});
});

describe('<Switch disabled={true} accessibilityState={{disabled: false}} />', () => {
it('should overwrite accessibilityState with value of disabled prop', () => {
expectRendersMatchingSnapshot(
'Switch',
() => (
<Switch disabled={true} accessibilityState={{disabled: false}}>
<View />
</Switch>
),
() => {
jest.dontMock('../Switch');
},
);
});
});

0 comments on commit 94a6a7f

Please sign in to comment.