-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could it be used in a Nativescript-Angular2 App? #57
Comments
Hey @magar91, thanks for this suggestion, I've added a ton of new features and bug fixes thanks to this issue! However, I haven't been able to actually run any unit tests with Nativescript and karma-typescript and I've tried two going down two paths:
I'm really out of my comfort zone here (not having done any Android development, ever) so I'm guessing the Android javascript environment needs to be included somehow... So far I've cloned https://github.com/NativeScript/nativescript-angular, installed module.exports = function(config) {
config.set({
frameworks: ['jasmine', 'mocha', 'chai', 'karma-typescript'],
files: [
'base.spec.ts',
'app/**/*.ts',
],
preprocessors: {
'**/*.ts': ['karma-typescript']
},
karmaTypescriptConfig: {
tsconfig: './tsconfig.json',
bundlerOptions: {
addNodeGlobals: false,
coverageOptions: {
exclude: /\.(d|tests)\.ts/
},
resolve: {
extensions: [
'.aot.ts',
'.ts',
'.js',
'.css',
'.ios.ts',
'.android.js',
'.android.css'
],
directories: ['node_modules', 'node_modules/tns-core-modules']
}
},
reports: {
'html': 'coverage',
'text-summary': ''
}
},
reporters: ['mocha', 'karma-typescript'],
browsers: ['Chrome']
})
} Contents of the import "tns-core-modules/globals";
import "nativescript-angular/zone-js/dist/zone-nativescript";
import "core-js";
import "application";
import { TestBed } from "@angular/core/testing";
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing"; Now I'm stuck at |
@erikbarke I've been working with nativescript and angular2 for a couple of months and I am kinda new with android development too. I also encountered some issues while trying to do any unit test with Nativescript-Angular2, mainly with the import of zone-js there is an open issue in the nativescrpit-angular2 github for this. module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'app/**/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [],
customLaunchers: {
android: {
base: 'NS',
platform: 'android'
},
ios: {
base: 'NS',
platform: 'ios'
},
ios_simulator: {
base: 'NS',
platform: 'ios',
arguments: ['--emulator']
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
} and my spec file is like this: import 'reflect-metadata';
import { Http, Headers, HttpModule, XHRBackend,
BaseRequestOptions, Response, ResponseOptions, RequestMethod } from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { LoginService } from '../../shared/login-service/login-service.service';
import { User } from '../../shared/user/user.model';
import { Config } from '../../shared/config';
import { inject, async, ComponentFixture, TestBed, fakeAsync, getTestBed } from '@angular/core/testing';
/*spec file continues here*/ I hope this can be of any help to you, and I'm very sorry I can't be more useful to you |
Hey, no worries 😃 |
Any news on this? I've tried quite a lot to make it work but seems to be out of my reach. |
Hey @mcrvaz, the bundling step will be disabled automatically if the I really tried making |
Hi @erikbarke, my test stack is Karma, Mocha, Chai and Sinon. Here is my karma.conf.js and tsconfig.json Also, seems that TestBed is not officially supported, so I'm not using it. I'm just instanciating the objects needed for testing manually. |
Please I need to do that with I'm following something like this: https://github.com/monounity/karma-typescript#configuration And @erikbarke explanation here: https://stackoverflow.com/a/39306795/3332734 The problem also was posted on StackOverflow: https://stackoverflow.com/q/50592311/3332734 I resumed that:
|
Like the title says could this be used for a Project in NativeScript - Angular2?
The text was updated successfully, but these errors were encountered: