@wordpress/notices
Version:
State management for notices.
50 lines (43 loc) • 1.13 kB
text/typescript
/**
* Internal dependencies
*/
import { getNotices } from '../selectors';
import { DEFAULT_CONTEXT } from '../constants';
describe( 'selectors', () => {
describe( 'getNotices', () => {
it( 'should return a consistent empty array for empty state', () => {
const state = {};
expect( getNotices( state ) ).toEqual( [] );
expect( getNotices( state ) ).toBe( getNotices( state ) );
} );
it( 'should return the notices array for the default context', () => {
const state = {
[ DEFAULT_CONTEXT ]: [
{ id: 'b', content: 'message 1' },
{ id: 'a', content: 'message 2' },
],
};
expect(
getNotices(
// @ts-expect-error Testing partial state
state
)
).toEqual( [
{ id: 'b', content: 'message 1' },
{ id: 'a', content: 'message 2' },
] );
} );
it( 'should return the notices array for a given context', () => {
const state = {
foo: [ { id: 'c', content: 'message 3' } ],
};
expect(
getNotices(
// @ts-expect-error Testing partial state
state,
'foo'
)
).toEqual( [ { id: 'c', content: 'message 3' } ] );
} );
} );
} );