Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing dependency with td.replace(path, replacement) doesn't work #249

Closed
chrisregner opened this issue May 20, 2017 · 4 comments
Closed

Comments

@chrisregner
Copy link

Here, I've used td.replace('./virtualClassnames', virtualCns) to completely replace the object that virtualClassnames exports:

// convertVirtualClassnames.spec.js
describe('convertVirtualClassnames()', function () {
    let cvc
    const virtualCns =  {
        virtualCnA: 'cnA cnB',
        virtualCnB: 'virtualCnA classC',
    }

    beforeEach('replace virtualClassnames dependency', function () {
        td.replace('./virtualClassnames', virtualCns)
        cvc = require('Services/cn/convertVirtualClassnames').default
    })

    it.only('converts any virtual class names that are found into actual class names', function () {
        expect(cvc('virtualCnA')).to.equal(virtualCns.virtualCnA)
    })
})

Here's the function being tested, I've logged the supposedly replaced virtualClassnames but it doesn't output as expected

// convertVirtualClassnames.js
import virtualClassnames from './virtualClassnames'

function convertVirtualClassnames(classNames?:string): string {
    // outputs { test: 'test' },
    // expected { virtualCnA: 'cnA cnB', virtualCnB: 'virtualCnA classC' }
    console.log(virtualClassnames)

    // process and return something here..
}

export default convertVirtualClassnames

The actual virtualClassnames:

// virtualClassnames.js
const virtualClassnames = { test: 'test' }

export default virtualClassnames
@chrisregner
Copy link
Author

chrisregner commented May 21, 2017

Furthermore, the following:

td.replace('./someFunc')

outputs this:

Error: Cannot find module './someFunc' from 'C:\myProjRootDir'

which is surprising because both someFunc and the file where I'm calling td.replace from is in a sub-directory of myProjRootDir.

So I tried to pass td.replace a path that allows it to resolve from root directory, and it outputted this:

SyntaxError: Unexpected token export

Is it because I'm using Webpack? I think why td.replace failed to import at first because it isn't aware of the import resolvers I've passed to Webpack. However, I don't know why it gave a syntax error after the import was resolved. I must have overlooked something.

@searls
Copy link
Member

searls commented May 30, 2017

This isn't enough for me to go on. Please post a minimal example project we can work from to reproduce.

@chrisregner
Copy link
Author

Okay will do. I'll post it here as soon as it's ready.

@chrisregner
Copy link
Author

Sorry, I've tried to do the same thing on a different project and it worked. There must've been something wrong in my previous development environment setup. I'm closing this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants