it('should not shorten text unless typeof children is string', () => {
const result = shallow(<ShortParagraph><b>{text}</b></ShortParagraph>);
expect(result.children().text()).toEqual(text);
});
Codewars currently doesn't allow authors to specify a test framework, but the code runner service does support other test frameworks including Jest for JS/TS. When this kata and other React kata had to be updated from Node 6.x, I had to specify the React environment available in Node 10.x/12.x using a hack because the default environment no longer includes React. The new React environment uses Jest.
@mikhama
Until Codewars supports the configuration in the kata editor, you need to use some hack using a special comment. To create a kata with React, you need to set the language version to Node 12.x and add the following to Preloaded:
// HACK The following special comment allows React with Jest.
// This is a temporary hack until Codewars supports test framework choices.
// @config: env-set node12_react
This will tell the code runner to use the React environment instead.
The tests should look something like the following:
import React from "react";
import Adapter from "enzyme-adapter-react-16";
import Enzyme, { shallow } from "enzyme";
Enzyme.configure({ adapter: new Adapter() });
import FooComponent, { foo } from "./solution";
// Then write tests
Love the idea of doing some React on here. We need more of it.
However, I'm not sure this kata is a good representation of how "Lifting Up State" should work. The state (the list of inhabitents in each location, in this case) should be stored in "their closest common ancestor", which would be Universe. The Universe should pass two props (a transport handler and a list) down to Planet and Starship. That setup would eliminate the need for componentWillReceiveProps (which is now considered unsafe)
It might be useful to write a test against hard coding 110 straight into the HOC instead of reading the value from the second parameter passed to withPriceModel.
I enjoyed the atmosphere from the Code Dojo as well. Make sure you ping me again when you organise the next one ;)
the most legible solution I've reviewed so far; great work!
Hi, @richkotze!
Thanks for a nice kata.
But, what if typeof childten isn't a string?
This comment is hidden because it contains spoiler information about the solution
Thank you very much!
Codewars currently doesn't allow authors to specify a test framework, but the code runner service does support other test frameworks including Jest for JS/TS. When this kata and other React kata had to be updated from Node 6.x, I had to specify the React environment available in Node 10.x/12.x using a hack because the default environment no longer includes React. The new React environment uses Jest.
@mikhama
Until Codewars supports the configuration in the kata editor, you need to use some hack using a special comment. To create a kata with React, you need to set the language version to
Node 12.x
and add the following to Preloaded:This will tell the code runner to use the React environment instead.
The tests should look something like the following:
You need to import react in both solution and test case code views.
Don't think Jest is available in codewars.
See the package.json for available testing frameworks: https://github.com/codewars/codewars-runner-cli/blob/master/package.json
Hello @richkotze,
Could you help me with adding React task to Codewars?
How to add React and Jest to environment?
I've tried to do that, but Codewars complaing on "import React".
This comment is hidden because it contains spoiler information about the solution
In any case it gives the same error, even if the file is empty ----> "Invariant Violation: Minified React error #105;"
This comment is hidden because it contains spoiler information about the solution
.
This comment is hidden because it contains spoiler information about the solution
Love the idea of doing some React on here. We need more of it.
However, I'm not sure this kata is a good representation of how "Lifting Up State" should work. The state (the list of inhabitents in each location, in this case) should be stored in "their closest common ancestor", which would be
Universe
. TheUniverse
should pass two props (a transport handler and a list) down toPlanet
andStarship
. That setup would eliminate the need forcomponentWillReceiveProps
(which is now considered unsafe)Brilliant kata to get someone started with HOC's.
It might be useful to write a test against hard coding 110 straight into the HOC instead of reading the value from the second parameter passed to withPriceModel.
I enjoyed the atmosphere from the Code Dojo as well. Make sure you ping me again when you organise the next one ;)
We're validating the input value now.
Loading more items...