I have recently migrated my react app from material-ui v3 to v4 and replaced '#material-ui/core/styles' with '#material-ui/styles',for testing we have used jest and enzyme.Tests failed after migration.How can I resolve this issue? Errors are as follows:
Warning: Material-UI: the styles argument provided is invalid.
You are providing a function without a theme in the context.
One of the parent elements needs to use a ThemeProvider.
Error: Uncaught [TypeError: theme.spacing is not a function]
Full DOM rendering › encountered a declaration exception
TypeError: theme.spacing is not a function
17 | },
18 | selectEmpty: {
> 19 | marginTop: theme.spacing(2),
| ^
20 | },
Material UI old version is like import { makeStyles } from '#material-ui/styles';
but they have updated new version like that import { makeStyles } from '#material-ui/core/styles'
You have to wrap every test with ThemeProvider. This resolves the issue.
Example:
wrapper = mount(
<ThemeProvider>
<Dropdown handleSelect={handleSelectSpy} options={options} />
</ThemeProvider>,
);
Related
I'm trying use karate for e2e tests and have started with a minimal setup. I want to create some config items in karate-config.js for use in the tests but karate is reporting that file is not a js function and hence the test fails trying to get the config:
Warning: Nashorn engine is planned to be removed from a future JDK release
12:16:35.264 [Test worker] WARN com.intuit.karate - not a js function or feature file: read('classpath:karate-config.js') - [type: NULL, value: null]
---------------------------------------------------------
feature: classpath:karate/insurer.feature
scenarios: 1 | passed: 0 | failed: 1 | time: 0.0163
---------------------------------------------------------
HTML report: (paste into browser to view) | Karate version: 0.9.1
file:/Users/srowatt/dev/repos/api/price-service/build/surefire-reports/karate.insurer.html
---------------------------------------------------------
-unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
org.opentest4j.AssertionFailedError: -unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
This is my karate-config.js:
function fn() {
return {
priceBaseUrl: "http://localhost:8080"
};
}
This is my insurer.feature test:
Feature: which creates insurers
Background:
* url priceBaseUrl
* configure logPrettyRequest = true
* configure logPrettyResponse = true
Scenario: basic roundtrip
# create a new insurer
Given path 'insurers'
And request { name: 'Sammy Insurance', companyCode: '99' }
When method post
Then status 201
And match response == { resourceId: '#number', version: 0, createdBy: 'anonymousUser' }
* def insurerId = response.resourceId
# get insurer by resource id
Given path 'insurers', insurerId
When method get
Then status 200
And match response == { id: '#(id)', name: 'Sammy Insurance', companyCode: '99' }
This is the InsurerTest.java test runner:
package karate;
import com.intuit.karate.junit5.Karate;
class InsurerTest {
#Karate.Test
public Karate testInsurer() {
return new Karate().feature("classpath:karate/insurer.feature");
}
}
Please use below code in the karate-config.js
function() {
return priceBaseUrl='http://localhost:8080';
}
When I see this:
Warning: Nashorn engine is planned to be removed from a future JDK release
I suspect you are on Java 9 or 11 ? To be honest, we haven't fully tested Karate on those versions of Java yet. Would it be possible for you to confirm that Java 8 (maybe 9 / 10 also) is OK.
That said, we are interested in resolving this as soon as possible, so if you can submit a sample project where we can replicate this, please do so: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
EDIT: Karate 1.0 will use GraalVM instead of Nashorn and will run on even JDK 16: https://software-that-matters.com/2021/01/27/7-new-features-in-karate-test-automation-version-1_0/
I'm trying to make pagination in Vuejs 2 project
i write a code like in this demo
https://jsfiddle.net/os7hp1cy/48/
it's work fine in Vuejs 1 (vue-1.0.23)
however when i use this code with Vuejs 2 (vue#2.4.2) it's show me this error message :
[Vue warn]: Property or method "paginate" is not defined on the instance
but referenced during render. Make sure to declare reactive data
properties in the data option.
(found in <Root>)
how i can fix that error
thanks
In your code have this line:
v-for="user in users | filterBy searchKey | paginate"
And all filters are removed in vue2 so your code won't work https://v2.vuejs.org/v2/guide/migration.html#Filters
Moreover, you should not mount vue to body:
[Vue warn]: Do not mount Vue to <html> or <body> - mount to normal elements instead.
You can check my working code: https://jsfiddle.net/os7hp1cy/187/
I've forked #imcvampire's code and make a working version for Vue 2 due to this filter migration https://v2.vuejs.org/v2/guide/migration.html#Filters-Outside-Text-Interpolations-removed.
paginate method is moved to computed:
paginate: function() {
if (!this.users || this.users.length != this.users.length) {
return
}
this.resultCount = this.users.length
if (this.currentPage >= this.totalPages) {
this.currentPage = this.totalPages
}
var index = this.currentPage * this.itemsPerPage - this.itemsPerPage
return this.users.slice(index, index + this.itemsPerPage)
}
WARNING: I didn't apply the text filter, just the pagination first.
https://jsfiddle.net/c1ghkw2p/
I was adding a snapshot test to a piece of React code, and I incurred in this error:
Unexpected node type: SequenceExpression (This is an error on an internal node. Probably an internal error. Location has been estimated.)
The code transpiles and works just fine, and the AST explorer doesn't warn me about anything.
Before this new test, no other test gave me any sort of similar error, and we have quite a few of them in our codebase.
I tried to reinstall jest, reinstall babel-jest, remove and reinstall all modules (using yarn --pure-lock), upgraded both jest and babel-jest to the latest version (20.0.1 for both), rinsed and repeated.
Nothing worked.
This occurs only when I try to collect the coverage (with --coverage), while the minimal snippet it occurs with is:
import { tint } from 'polished'
import styled from 'styled-components'
export default styled.label`
background: ${({ x, y }) => (x ? tint(0.3, y.a) : y.b)};
`
Here's what i've found:
This is an issue with jest code coverage being able to understand styled components and polished. I am using babel-plugin-polished with the following in my babelrc:
"plugins": [ "polished" ]
But still if you call export on a value, and do not also use that value in an object or exported object, it will fail.
Fails:
export const charcoalBlue = rgb(104, 131, 145);
Doesn't fail:
export const charcoalBlue = rgb(104, 131, 145);
const colors = { charcoalBlue }
So my solution has been to ignore my style files, or simply ensure I'm using the values I create and not just exporting them.
One way to ignore the style files, place this in your package.json:
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!**/*.styles.js",
]
}
And name your style files {ComponentName}.styles.js
Hope this helps!
I came across the same issue!
I fixed it by working around it:
import styled, {css} from 'styled-components';
styled.label`
${({x,y}) => x
? css`background: tint(0.3, y.a);`
: css`background: ${y.b};`
}
`;
I'm trying webpack 2 code splitting.
According to this doc: https://webpack.js.org/guides/code-splitting-require/
the following code should include some.css into a new chunk named 'something'
require.ensure([], function(require) {
require('some.css');
}, 'something');
but when I run it, I get this error:
ERROR in ./src/index.ts
(4,9): error TS2339: Property 'ensure' does not exist on type 'NodeRequire'.
Any idea about how to fix it?
Thanks
The way I solved this was by creating my own interface - WebpackRequire - which extends NodeRequire with ensure1.
interface WebpackRequire extends NodeRequire {
ensure(
dependencies: string[],
callback: (require: WebpackRequire) => void,
errorCallback?: (error: Error) => void,
chunkName?: string
): void;
};
If you've only got a single instance of require.ensure, you can then type cast it to a WebpackRequire using (require as WebpackRequire).ensure, but since I used it multiple times in a module, I created local require at the top scope of the module, type cast as WebpackRequire, like this:
const require: WebpackRequire = (window as any).require;
1I got the types of ensure from the Webpack docs
I required a javascript document which then did the require. Not exactly the nicest solution, but it did work
I have an issue with the webstorm IDE. It seems like that webstorm always shows the error of invalid argument in the IDE, but the typescript compiler do not show such error; I'm starting to believe that this issue is with the IDE.
I have the following repository: https://github.com/danielmahadi/modular-typescript
There are 4 typescript files:
customerModel.ts => customer model file
export class User{
constructor(public id: string, public name: string){}
}
converter.ts => convert json data to customer model
import model = require('./customerModel')
export function convertToUser(data: any) : model.User {
return new model.User(data.id, data.name);
}
printer.ts => print the customer model to console
import model = require('./customerModel')
export function print(data : model.User) : void {
console.log('PRINTING...');
console.log(data);
}
app.js => the entry point for the app.
import converter = require('./converter');
import printer = require('./printer');
var d = {
id: '123', name: 'Test'
}
var user = converter.convertToUser(d);
printer.print(user);
Environment:
webstorm 7.0.3, build number: WS-133.434
Mac OSX with Maverick
Typescript version: 0.9.5.0
Typescript file watcher setting for typescript:
Typescript compiler => tsc --module commonjs --sourcemap $FileName$
If you open this with webstorm IDE, you will see that in the app.ts line 15, the "user" is always underlined with red line with the error "Argument type './customerModel'.User is not assignable to parameter type model.User".
This is what the error looks like:
Has anyone else encountered this before? Am I doing something wrong, or this is just another webstorm bug?
Definitely an error in webstorm. Would appreciate it if you report it here : http://youtrack.jetbrains.com/issues/WEB and put a link so we can vote on it.
Please try WebStorm 8 EAP - the bug seems to be fixed there