Reputation: 849
I'm having a problem where Jest isn't running the test for each item in the array.
const newUniqueLangs = ['de', 'de', 'de', 'de', 'de', 'de', 'it', 'it', 'it', 'it', 'it', 'it', 'nl', 'nl', 'nl', 'nl', 'nl', 'nl', 'fr', 'fr', 'fr', 'fr', 'fr', 'fr', 'en', 'en', 'en', 'en', 'en', 'en' ]
The reason for the duplicated items in this array is due that each trigger should have it's own 'language', so I have to duplicate it depending on how many triggers there are in userTriggerFile. In this case there should be 6 for each language.
// UserTriggerFile is a big dictionary and I'm accessing each message in this
// Trigger messages is just an array of messages.
it('has a valid triggers for each particular language', () => {
newUniqueLangs.forEach(function (lang) {
for (const key in userTriggerFile) {
userTriggerFile[key].forEach(function (obj) {
if (obj.Message) {
if (obj.LocaleMessage) {
expect(triggerMessages).toContain(`${obj.Message + '-' + lang}`)
}
}
})
}
})
})
The problem is that this test should be executed for every item in this array but it isn't. I believe this is a problem with the nested for loop. I've been looking at 'test.each' in Jest and maybe it's because I am missing this?
Upvotes: 1
Views: 353
Reputation: 849
Answer, I was misplacing the 'it' statement:
describe('test triggers', () => {
newUniqueLangs.forEach(function (lang) {
for (const key in userTriggerFile) {
userTriggerFile[key].forEach(function (obj) {
if (obj.Message) {
if (obj.LocaleMessage) {
it('has a valid triggers for each particular language', () => {
expect(triggerMessages).toContain(`${obj.Message + '-' + lang}`)
})
}
}
})
}
})
})
Upvotes: 1