When I run npm test I get this error :
Test suite failed to run
RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.
I want to use Jest to run tests for Android plateform only because I'm not developing for iOS.
I added this code on top of my test file to mock all the test on Android :
jest.mock('Platform', () => {
const Platform = require.requireActual('Platform');
Platform.OS = 'android';
return Platform;
})
IMPORTANT : It has to be on top of all the test functions
Related
I have a serverless-framework project that is using the serverless-bundle package so that I can use ES6 imports and exports.
I currently have a failing test. When I click on the "Debug" link in Visual Studio Code, the debug session fails for the following reason on line 1 of my test code: SyntaxError: Cannot use import statement outside a module
The test code I'm working on is located here: https://github.com/groffcole/art-center-service/blob/master/ports/GalleriesHttpPort.test.js
What can I do to fix this issue?
Thanks.
try using const "" = require() and see if that works. if it does, what version of nodejs do you have installed? and did you set it up to use es6 imports? ES^ imports are still experimental as of node 13
https://nodejs.org/api/esm.html#esm_introduction
https://nodejs.org/dist/latest-v13.x/docs/api/modules.html#modules_module_exports
let func1 = ()=>{
return "Hello"
}
let func2 = ()=>{
return "World"
}
module.exports ={func1:func1,func2:func2}
I have my testcafe test which is running well via terminal with
testcafe chrome jira-web-front\src\test\script\testcafe
I would like to be able to run it inside intelliJ js editor by clicking on the play button:
When I execute my test by clicking on the green play button I have:
I have some jest tests also in my project.
I tried to install intelliJ testcafe plugin but it didn't help.
Any idea about this?
Thanks
The logic currently used by JavaScript support plugin for detecting what test runner is available for a given test file is based on dependencies declarations in package.json nearest to this file: it looks for known test runners listed there and tries to run the most suitable one. As IDEA
doesn't provide any support for TestCafe (https://youtrack.jetbrains.com/issue/WEB-30315), you can't expect it to run TestCafe from a gutter; it runs your tests with jest because you have it in your dependencies list.
To run test using the run configuration provided by testcafe plugin, you need right-clicking the test in editor:
This plugin doesn't support running tests from gutter, neither it supports debugging.
Note that you can use VS Code recipes to debug TestCafe in IDEA. Namely, you need Node.js Run configuration like the following:
where JavaScript file: is set to a path to your locally installed testcafe module, e.g. node_modules\testcafe\bin\testcafe.js, and Application parameters: are testcafe cli args, like
chrome myTestFile.js
New to nodejs testing.
I have a nodejs server that runs some complex server side logic, and I'm looking at building a unit test runner for that code. I do not want to run the server and tests sending it requests though, as that doesn't expose all the modules and functions I want to test on the server side. That will be more like integration testing. I just want to import those server side files, which are written as AMD modules, and call their functions one by one in unit tests.
What's the best way to go about doing this?
You will want to start by installing a unit-test and assertion framework to your current project. Then you will also want to add requirejs (r.js).
We are currently using mochajs for unit-testing with should as the assertion library. Both have great adoption and feature support for testing Node.js.
npm install mochajs shouldjs requirejs --save-dev
This will add three packages to your local node_modules as well as save them inside your package.json's devDependencies.
Go ahead and setup a unit test directory in your project and create a new test file, [your_module_name]_test.js:
const should = require('should'),
foo = require('foo');
describe('foo', () => {
it('returns the letter a', () => {
foo().should.eql('a');
});
});
In the test file you will want to require the module under test and then unit-test as usual.
You can then run the test through r.js
./node_modules/requirejs/bin/r.js [your_test_dir]/[your_module_name]_test.js
You can also install mochajs globally and then simply run the mocha command instead of using the bin inside of your local node_modules.
Best of luck, and hope this helps.
I'm trying to prototype an Electron app using Angular 2 (configured with the latest webpack-based angular cli) for the gui, but I'm stuck since I don't get how to import Electron api in my angular2 components. Specifically I want to be able to open a new BrowserWindow at the click on a button in the ui... so:
<button type="button" (click)="openNewWindow()">
open
</button>
and in my component:
openNewWindow() {
let appWindow = new BrowserWindow({width: 800, height: 600});
appWindow.loadUrl('http://www.google.com');
}
but... how can I import BrowserWindow?!
By using:
import { BrowserWindow } from 'electron';
I get a "no module error" and by following the answer to this question: Webpack cannot find module 'electron' I get:
syntax error near unexpected token ( var electron = require('./')
What should I do?
ps. by running "electron ." without the BrowserWindow import the app is working properly
Run the command npm install electron #types/electron
Then import it normally using
import { ipcRenderer } from 'electron'.
If you run into any problems, try to run npm eject, a webpack.config.js will be generated, add "target": "electron-renderer" at the top of module.exports
Set this in index.html
<script>
var electron=require("electron");
</script>
Add this line in typings.d.ts file
declare var electron: any;
Use inside the component like this example:
const {ipcRenderer, clipboard} = electron;
clipboard.writeText('Electron is ready!!');
I tried to work with angular-cli and Electron and was not able to make them to work together. It's the reason why I started the following project: https://github.com/osechet/angular-tour-of-heroes-webpack
It integrates Angular 2 with webpack and Electron. It's based on the Angular 2 tutorial (with unit tests). When running Electron in dev mode (npm run start.desktop), it livereloads the sources.
To complete the answer given by chaouechi souhail.
As I understand his answer aims to solve the situation where the angular app is directly embedded in the electron app.
If for some reason you are using two separate projects whereof one is the electron app which embeds the other as a web app using one of electron's webview components you might find the following approach helpful aswell.
In your electron app you'll have something like
<webview id="webview" src="http://localhost:4200/" nodeintegration></webview>
In your angular project you
install the electron nodejs module, ie npm install electron . The types module mentioned by chaouechi might suffice, I do not know.
you eject the webpack config through ng eject
in webpack's config (webpack.config.js) you define electron as an external module such that webpack does not attempt to build it into the ng app, extend the exports as below
module.exports = {
//...
externals: {
electron: "require('electron')", // tell's webpack how to import the electron module within your angular app after being packed
//...
},
//...
}
Now, in your ng components, it should be possible to include electron classes as follows: import { remote } from "electron";
Update as of 3/20/2021
Angular CLI v11
This information was pretty hard to find so I'm answering in as many places as I can that has outdated info.
There are a few simple steps.
Add #angular-builders/custom-webpack (this saves you from ejecting angular's current webpack file which we don't really want to touch).
npm i -D #angular-builders/custom-webpack
Modify your angular.json to use the package you installed and a custom webpack file that you create (more detailed instructions on the package's readme)
Make your custom webpack file look like this:
module.exports = {
target: "electron-renderer",
};
literally that's it. You don't need anything else in your webpack file and you should be all set to use electron as you expect. No need to create your own typings file or anything.
I have created a unit test in angular js,However I have no idea on how to setup node.js and Karma
So I downloaded the node.js from nodejs.org and installed it.
Open the command prompt and installed karma by executing "npm install karma"
It installed karma.But when I execute my angular js unit test case,it reports some errors
angular is undefined.
I followed the instructions as mentioned in this
http://bardevblog.wordpress.com/2013/07/28/setting-up-angularjs-angular-seed-node-js-and-karma/
Is there any where how to setup Karma and node js to execute angular unit test cases.
Please provide me the information
You can use the Yeoman generator for an Angular.js app to generate a new project and see how it is done there. Please follow the steps under "Usage" on the GitHub page to set up the new project. (For all questions yo is asking just hit enter.) Finally, type grunt test:client. This executes Karma configured with the karma.conf.js.
In your karma config file you need to define all the js files that needs to be loaded and the order in which you specify then is important! Example:
files : [
'source/lib/angular/angular.js', // angular first
'source/lib/angular/*.js', // then any other angular files (angular-mocks.js, angular-resource.js, angular-route.js ...
'source/lib/x2js/xml2json.min.js', // some libraries I used
'source/lib/jquery/jquery.js',
'source/lib/ui-bootstrap/ui-bootstrap.js',
'source/js/*.js', // my own js code
'source/tests/unit/*.js' // unit tests
]