File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
src/django_unicorn/static/unicorn/js Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ export function getComponent(componentNameOrKey) {
9191 if ( isEmpty ( component ) ) {
9292 const _component = components [ id ] ;
9393
94- if ( _component . key == componentNameOrKey ) {
94+ if ( String ( _component . key ) === String ( componentNameOrKey ) ) {
9595 component = _component ;
9696 }
9797 }
Original file line number Diff line number Diff line change 1+ import test from "ava" ;
2+ import { getComponent } from "../../../django_unicorn/static/unicorn/js/unicorn.js" ;
3+ import { components } from "../../../django_unicorn/static/unicorn/js/store.js" ;
4+ import { getComponent as getComponentUtil } from "../utils.js" ;
5+
6+ test ( "getComponent by key with type mismatch (existing string key, int lookup)" , ( t ) => {
7+ const component = getComponentUtil ( ) ;
8+ component . key = "123" ;
9+ components [ component . id ] = component ;
10+
11+ // Should find it even if we pass an integer
12+ t . truthy ( getComponent ( 123 ) ) ;
13+ } ) ;
14+
15+ test ( "getComponent by key with type mismatch (existing int key, string lookup)" , ( t ) => {
16+ const component = getComponentUtil ( ) ;
17+ component . key = 456 ;
18+ components [ component . id ] = component ;
19+
20+ // Should find it even if we pass a string
21+ t . truthy ( getComponent ( "456" ) ) ;
22+ } ) ;
You can’t perform that action at this time.
0 commit comments