Mocking getters from babell-ed libraries
See original GitHub issueI needed to mock storiesOf
member of @storybook/react. It looked like a simple function member and all went to this code
import * as StorybookReact from '@storybook/react';
const baseStoriesOf = ImportMock.mockFunction(StorybookReact, 'storiesOf');
But it did not work. After long hours of digging, I’ve found out what was that. Storybook-guys use babel to compile all code. So when we do import ... from '@storybook/react'
we actually import this ugly thing:
"use strict";
require("core-js/modules/es6.object.define-property");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "storiesOf", {
enumerable: true,
get: function get() {
return _preview.storiesOf;
}
});
// and so on
And nothing can help ImportMock.mockFunction
to replace [Getter]
.
Simplified example to reproduce the problem in gist.
Can we do something with that?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Mocking Static Methods - Spock Framework
A feature method must have at least one explicit (i.e. labelled) block ... When expecting a call to a getter method, Groovy property...
Read more >equals · GitHub Topics · GitHub
Java testing framework for testing pojo methods. It tests equals, hashCode, toString, getters, setters, constructors and whatever you report in issues ;).
Read more >Documentation - Ethers.js
The ethers.js library aims to be a complete and compact library for interacting with the Ethereum ... This is useful for calling getters...
Read more >Metaprogramming
The propertyMissing(String) method is only called when no getter method for the given property can be found by the Groovy runtime. For setter ......
Read more >(PDF) Mock objects for testing java systems - ResearchGate
expected. Listing 1shows an example usage of Mockito, one of the most popular mocking. libraries in Java (Mostafa and Wang 2014).
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
Unfortunately no 😦
In my case I’ve made it possible to replace external dependecy. Like
And in tests I do simply pass
sinon.stub()
intoreplacerForThing
-argument. So I had to change my own code to fix the issue@Vittly Have you found out some alternative to mock babel-ed libraries like that?