neotest-jest
neotest-jest copied to clipboard
Neotest-jest not working with describe.each
I'm trying to run some unit tests using neotest-jest, and I can't see the test results for some reason when using describe.each.
When running a test, such as:
import { sum } from '../src/AlgorithmsInTypescript/math'
describe('test sum module',() =>{
test('1 + 2 should equal 3',()=> {
const [a,b] = [1,2]
expect(sum(a,b)).toBe(3)
})
})
I can see the tests running fine.
However, if I run the following test:
import groupAnagrams from '../src/AlgorithmsInTypescript/GroupAnagrams'
const testCases = [
{
input: ['abc', 'cba', 'bca', 'xyz', 'yxz', 'zxy'],
output: [
['abc', 'cba', 'bca'],
['xyz', 'yxz', 'zxy'],
],
},
{
input: ['rat', 'tar', 'art', 'star', 'tars', 'rats'],
output: [
['rat', 'tar', 'art'],
['star', 'tars', 'rats'],
],
},
{
input: ['no', 'on', 'is', 'si', 'at', 'ta'],
output: [
['no', 'on'],
['is', 'si'],
['at', 'ta'],
],
},
{
input: ['bored', 'robed', 'debit card', 'bad credit', 'earth', 'heart'],
output: [
['bored', 'robed'],
['debit card', 'bad credit'],
['earth', 'heart'],
],
},
{
input: [''],
output: [['']],
},
{
input: ['a', 'b', 'c', 'a', 'b', 'c'],
output: [
['a', 'a'],
['b', 'b'],
['c', 'c'],
],
},
{
input: ['apple', 'paple', 'pale', 'leap', 'peal'],
output: [
['apple', 'paple'],
['pale', 'leap', 'peal'],
],
},
]
describe.each(testCases)('Test group anagrams', ({ input, output }) => {
it(`The input: ${input} should return ${output}`, () => {
const result = groupAnagrams(input)
const resultGroups = result.map((group) => new Set(group))
const expectedGroups = output.map((group) => new Set(group))
expectedGroups.forEach((expectedGroup) => {
expect(resultGroups).toEqual(
expect.arrayContaining([
expect.objectContaining({
size: expectedGroup.size,
...expectedGroup,
}),
]),
)
})
resultGroups.forEach((resultGroup) => {
expect(expectedGroups).toEqual(
expect.arrayContaining([
expect.objectContaining({ size: resultGroup.size, ...resultGroup }),
]),
)
})
})
})
I don't see the result if I run it via Neo-Test Jest, and it gives me a blue icon in the test explorer. It will work if I run the test via CLI.
Below is my lua config with lazy for Neotest jest showing how I configured it.
return {
-- Main testing dependency
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
"nvim-neotest/neotest-jest",
"Issafalcon/neotest-dotnet"
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-dotnet")({
discovery_root = 'solution'
}),
require("neotest-jest")({
jestCommand = "yarn test", -- Adjust this based on your npm command
jestConfigFile = "jest.config.js", -- If you have a Jest config file
env = { CI = true },
cwd = function(path)
-- Assuming tests are in a 'tests' folder
local relative_path = vim.fn.fnamemodify(path, ":~:.")
if string.match(relative_path, "^tests/") then
return vim.fn.getcwd()
end
return vim.fn.getcwd()
end,
}),
},
})
end,
}