Skip to content

Commit

Permalink
test cases: exploring non-literal child warning behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
glsignal committed Aug 31, 2023
1 parent 4644d1a commit dde6686
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/lexers/jsx-lexer.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assert } from 'chai'
import sinon from 'sinon'
import JsxLexer from '../../src/lexers/jsx-lexer.js'

describe('JsxLexer', () => {
Expand Down Expand Up @@ -535,6 +536,34 @@ describe('JsxLexer', () => {
)
done()
})

describe('when i18nKey is given', () => {
it('does not emit a warning when given a non-literal child', (done) => {
const Lexer = new JsxLexer({
transIdentityFunctionsToIgnore: ['funcCall'],
})
const content =
'<Trans i18nKey="testkey">Hi, {anotherFuncCall({ name: "John" })}</Trans>'
const spy = sinon.spy()
Lexer.on('warning', spy)
assert.equal(Lexer.extract(content)[0].defaultValue, 'test')
assert.isFalse(spy.called)
done()
})

it('does not emit a warning when defaults are specified and given a non-literal child', (done) => {
const Lexer = new JsxLexer({
transIdentityFunctionsToIgnore: ['funcCall'],
})
const content =
'<Trans i18nKey="testkey" defaults="test">{anotherFuncCall({ name: "John" })}</Trans>'
const spy = sinon.spy()
Lexer.on('warning', spy)
assert.equal(Lexer.extract(content)[0].defaultValue, 'test')
assert.isFalse(spy.called)
done()
})
})
})
})
})

0 comments on commit dde6686

Please sign in to comment.