![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
A utility library for testing React Native components using Detox
npm install --save-dev kompot
for example: App.js
:
import React from 'react';
import {Text} from 'react-native';
export class App extends React.Component {
render() {
return <Text>Hello world</Text>;
}
}
create a file called FirstTest.kompot.spec.js
:
const Kompot = require('kompot');
const component = Kompot.kompotRequire('App').App;
describe('Our first test', () => {
it('should mount the component', async () => {
await component.mount();
});
});
package.json
:"scripts":{
"start-kompot": "kompot -srk",
"test": "kompot -b <your-app-name> && detox test -c <your_configuration_name>",
}
Replace <your-app-name>
with the name of your app as you give to AppRegistry.registerComponent()
, and replace <your_configuration_name>
with your real configuration name as it appears in your package.json under detox
.
npm run start-kompot && npm run test
You should use this method instead of the native require in order to require your component.
const component = Kompot.kompotRequire('../App').App;
When you require a component, you get a component
object with the following props:
componentProps
value.You will need to mount your component on every tests:
it('should do something', async () => {
await component
.withProps({someProp: 'hello', onPress: () => console.log('hello!')})
.withMocks(['SOME_MOCK'])
.withTriggers(['someTrigger'])
.mount();
});
Mocks are just regular functions that you can pass to the KompotInjector in order to mock different functionalities. The mocks function should not reference variables outside of their scope, but they can require any file they want. You should define all the mocks directly in the KompotInjector object:
const someVarOutOfScope = 'hello';
component.kompotInjector({
SOME_MOCK: () => {
const JokeService = require('../fetchJokeService');
console.log(someVarOutOfScope) //will print undefined! don't reference out-of-scope vars!
JokeService.fetchJoke = async () => {
return Promise.resolve('This is a lame Chuck Norris joke')
}
}
})
If you want to activate some mock in some test, you need to mount the component with mocks:
it('should do something', () => {
component.withMocks(['SOME_MOCK']).mount();
});
You can create a default
mock that will be activated for all the tests:
component.kompotInjector({
default: () => {
const JokeService = require('../fetchJokeService');
JokeService.mockSomeThing = () => console.log('This will be mocked for all tests!');
}
});
Sometimes you need to trigger functions that during the tests, for example, if your react component has some method called scrollTo
and you want to test it, you can do using triggers. Triggers should be supplied to the kompotInjector just like mocks. If you need to interact with you component, you can use the savedComponentRef
global.
component.kompotInjector({
someTrigger: () => {
global.savedComponentRef.scrollTo('bottom');
}
});
Inside your KompotInjector scope you can make use of the following globals:
global.componentProps
: The props object that will be pass to the component. This object will be merged with all the props you supply to component.withProps()
. You can use this object to pass to your component some complex props, like es6 classes.
global.savedComponentRef
: The mounted component ref.
Example:
component.kompotInjector({
SOME_MOCK: () => {
const JokeClass = require('./Joke');
global.componentProps.joke = JokeClass;
global.savedComponentRef.scrollTo('bottom');
}
})
Injects the given mocks and triggers into the app.
component.kompotInjector({
default: () => { //the default function will be called for each test.
const JokeService = require('../fetchJokeService');
JokeService.fetchJoke = async () => {
return Promise.resolve('A mocked joke fetched from the joke service!');
}
},
MOCK_LAME_JOKE: () => { //will be called only if the componet is mounting with the 'MOCK_LAME_JOKE' mock.
const JokeService = require('../fetchJokeService');
JokeService.fetchJoke = async () => {
return Promise.resolve('This is a lame Chuck Norris joke')
}
}
})
usage: kompot [-h] [-s] [-k] [-r] [-b appName]
[-t {react-native-navigation}] [-i filePath]
[-l filePath]
Optional arguments:
-h, --help Show this help message and exit.
-s, --start Launch react-native's packager.
-k, --kill Kill server and packager if needed.
-r, --run-server Start the Kompot server on port 2600
-b appName, --build appName
Scan the project for *.kompot.spec.js and process
them. app name should be the same name that you pass
to AppRegistry.registerComponent()
-t {react-native-navigation}, --app-type {react-native-navigation}
Application type.
-i filePath, --init-root filePath
A path to an initialization file, for custom
initializaion of the root component.
-l filePath, --load filePath
A path to a file that will be loaded before the
mounting of the component. Put all global mocks in
this file
const Kompot = require('kompot');
//require the component that we want to test:
const component = Kompot.kompotRequire('../ChuckNorrisJokesPresenter');
//write some mocks:
component.kompotInjector({
MOCK_LAME_JOKE: () => {
const JokeService = require('../fetchJokeService');
JokeService.fetchJoke = async () => {
return Promise.resolve('This is a lame Chuck Norris joke')
}
}
})
describe('ChuckNorrisJokesPresenter', () => {
it('Should fetch a joke', async () =>
await component
.withProps({someProp: 'test'})
.withMocks(['MOCK_LAME_JOKE']) //use the mock that we specified above
.mount();
await expect(element(by.id('chuckNorisJoke'))).toHaveText('"This is a lame Kompot joke"');
})
});
FAQs
A utility library for testing React Native components using Detox
The npm package kompot receives a total of 3 weekly downloads. As such, kompot popularity was classified as not popular.
We found that kompot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.