Fails to import modules inside imported module from tests
See original GitHub issue- Issue When ever i link a module from my typescript source files, it seems like the modules inside that said imported module are not imported.
Heres an example test
import { User } from './../src/types/models';
import Api from '../src/api';
import { t } from '../src/configs/i18n'
const api = new Api()
// beforeEach()
describe('Api client', () => {
it('Should return wilomgx as a user', (done) => {
const login = api.getUserByLogin({
user:'wilomgfx',
pw:'wilomgfxis2op4you'
})
login.then(({data} : {data: User}) => {
expect(data).toBeInstanceOf(User)
expect(data.fullName).toBe('William Graphics')
done()
})
.catch(e => done(e))
})
//...more tests
}
My config
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/test/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js"
To make it work i have to import my compiled javascript from my build folder
import { User } from './../build/types/models';
import Api from '../build/api';
import { t } from '../build/configs/i18n'
const api = new Api()
// beforeEach()
describe('Api client', () => {
it('Should return wilomgx as a user', (done) => {
const login = api.getUserByLogin({
user:'wilomgfx',
pw:'wilomgfxis2op4you'
})
login.then(({data} : {data: User}) => {
expect(data).toBeInstanceOf(User)
expect(data.fullName).toBe('William Graphics')
done()
})
.catch(e => done(e))
})
//...more tests
}
Heres the imported file that is causing the error when referencing the typescript file from the src folder
import I18n from 'react-native-i18n'
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
I18n.fallbacks = true
//code to set translations, not relevant here
- Expected behavior
Work ? I dont know, maybe my configs are wrong… but it wont work for required typescript files. Tried to use an other file with some other random imported file, and it wont work either.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
python - Trouble importing a module that imports a module
When you try to import a module ( import module_a ), Python will search in order in every directory listed in sys.path ....
Read more >ModuleNotFoundError: no module named Python Error ...
Make sure imported modules are installed. Take for example, numpy . You use this module in your code in a file called "test.py"...
Read more >Import-Module (Microsoft.PowerShell.Core)
The Import-Module cmdlet adds one or more modules to the current session. Starting in PowerShell 3.0, installed modules are automatically imported to the ......
Read more >unittest: Can't import module in package : r/learnpython
main.py imports submodule . In test_app.py I'd like to test submodule.py, so I do something like this in a test: import app instanceOfClass ......
Read more >pytest import mechanisms and sys.path / PYTHONPATH
pytest as a testing framework needs to import test modules and conftest.py files for execution. Importing files in Python (at least until recently)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@wilomgfx the import is incorrect. Use
I’ve sent a PR to your repo.
please create a minimal repo which reproduces this issue