File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { useMemo } from '@wordpress/element';
33import { __ } from '@wordpress/i18n' ;
44import Clipboard from '../common/Clipboard' ;
55
6- export default function ( { flag } : { flag : string } ) : JSX . Element {
6+ const JsSnippet = ( { flag } : { flag : string } ) => {
77 const jsSnippet = useMemo ( ( ) => {
88 return `import domReady from '@wordpress/dom-ready';
99domReady(function () {
@@ -22,4 +22,6 @@ domReady(function () {
2222 < Snippet data = { jsSnippet } language = { 'typescript' } />
2323 </ div >
2424 ) ;
25- }
25+ } ;
26+
27+ export default JsSnippet ;
Original file line number Diff line number Diff line change 1+ import JsSnippet from '../JsSnippet' ;
2+ import { render , screen } from '@testing-library/react' ;
3+ import '@testing-library/jest-dom' ;
4+
5+ describe ( 'JsSnippet component' , ( ) => {
6+ test ( 'should render JsSnippet correctly with passed flag prop' , async ( ) => {
7+ render ( < JsSnippet flag = "testFlag" /> ) ;
8+ const result = screen . getByText ( / J a v a S c r i p t S n i p p e t / i) ;
9+ expect ( result ) . toBeInTheDocument ( ) ;
10+ } ) ;
11+
12+ test ( 'should render the correct JavaScript snippet with the passed flag' , async ( ) => {
13+ render ( < JsSnippet flag = "testFlag" /> ) ;
14+ const snip = screen . getByText ( / .c o d e b F e a t u r e F l a g s .i s E n a b l e d / i) ;
15+ expect ( snip ) . toBeInTheDocument ( ) ;
16+ } ) ;
17+
18+ test ( 'should update the JavaScript snippet when the flag prop changes' , async ( ) => {
19+ const { rerender } = render ( < JsSnippet flag = "testFlag1" /> ) ;
20+ let snip = screen . getByText ( / t e s t F l a g 1 ' / i) ;
21+ expect ( snip ) . toBeInTheDocument ( ) ;
22+ rerender ( < JsSnippet flag = "testFlag2" /> ) ;
23+ snip = screen . queryByText ( / ' t e s t F l a g 1 ' / i) ;
24+ expect ( snip ) . toBeNull ( ) ;
25+ snip = screen . getByText ( / ' t e s t F l a g 2 ' / i) ;
26+ expect ( snip ) . toBeInTheDocument ( ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments