question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails to import modules inside imported module from tests

See original GitHub issue
  • Issue image 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kulshekharcommented, Mar 24, 2017

@wilomgfx the import is incorrect. Use

import * as I18n from 'react-native-i18n';

I’ve sent a PR to your repo.

2reactions
kulshekharcommented, Mar 24, 2017

please create a minimal repo which reproduces this issue

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found