ngrx/effects unit tests using jasmine-marbles - testing

When I try to use either cold or hot functions from jasmine-marbles, I keep getting TypeError: Class constructor Observable cannot be invoked without 'new'. Anybody know how to resolve this error? Here is what I have below.
import { hot, cold } from "jasmine-marbles";
import { Observable } from "rxjs/Observable";
const myAction = hot("--a-", { a: "TEST" };

I started to get this error after i changed "target" property in tsconfig.json (at project root) to "es6", thus i restored to old good "es5"

Related

How to import node-java and use it correctly?

Now I am trying to call our APIs in our own Jar.
In VS Code extension example project, I tried to npm install java to install it in modules dir.
In my extension.ts it looks like below:
import * as vscode from "vscode";
import * as java from "java";
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log(
'Congratulations, your extension "test-ext" is now active!'
);
context.subscriptions.push(
vscode.commands.registerCommand("test-ext.callLocalJar", async () => {
console.log('test caller start.');
java.classpath.push("testapis.jar");
console.log('test caller start.');
}
)
);
}
// this method is called when your extension is deactivated
export function deactivate() {}
But now I got a failure in the very beginning when activating it...
error:
Activating extension 'boyka.test-ext' failed:
Cannot find module 'c:\Users\boyka\Workspaces\test-ext\build\Release\nodejavabridge_bindings.node'.
My package.json is like
"dependencies": {
"java": "^0.12.2"
}
I am not sure of the root cause, tried to research and add Java home to PATH but luck.
Anyone has this node-java usage experience that could help? Will appreciate that!
https://github.com/joeferner/node-java
Thanks
b.

An updated approach to testing vuex actions

In the "Testing Actions" documentation, there is a recommendation to use inject-loader in order to mock entire module imports, and their respective dependencies, when unit testing.
For example, you can mock the ../api/shop import found inside the ./actions file with the following:
const actionsInjector = require('inject-loader!./actions')
// create the module with our mocks
const actions = actionsInjector({
'../api/shop': {
getProducts (cb) {
setTimeout(() => {
cb([ /* mocked response */ ])
}, 100)
}
}
})
Unfortunately, that package does not support Webpack 5.
Is there an updated approach, or alternative package, that is recommended?
Thanks #Estus Flask.
The clarification/mixup was that, whilst I was using vi.mock, and it's auto-mocking algorithm :
"...will mock the module itself by invoking it and mocking every
export."
i.e. it still runs the import statements. To prevent this, a factory must be provided (see documentation), e.g.:
vi.mock('module', <factory-here>)
Which then replaces the entire file import.

How to mock vuex functions with no direct access?

So I have run into quite a test problem.
To Summarize:
A while back I created a private npm Module, that manages and create a vuex store and injects it as a module into the main vuex store.
Now I want to mock a specific function of that vuex module in my test but that doesn't work.
I tried this:
store.getters.getSomething = jest.fn(() => "stuff);
But that results in this error:
TypeError: Cannot set property getSomething of #<Object> which has only a getter
Now did a little digging, and I here you can see where this getter comes from:
First there is a simple vuex module definition:
//vuexModule this is not accessible outside of the npm module
getters:{
getSomething: (state)=>{ return "stuff"}
}
export { getters }
Now this is imported into this class:
//storeProvider //this is exposed by the npm package
import vuexModule from "./vuexModule";
export default class StoreProvider {
constructor(vuexStore, vuexModuleName = "someStore") {
this.vuexStore = vuexStore;
this.vuexStore.registerModule(vuexModuleName, VuexConfigStore);
}
So this class will generate a vuex module using the previously defined module.
Now the whole thing is added to the main vuex store in the actual application.
Note: this code is now the actual application and not in the npm package.
import StoreProvider from "someNpmModule";
import mainStore from "vuexPlugin";
const storeProvider = new StoreProvider(store);
//later in main:
new Vue({ mainStore })
So the question is: How can I mock getSomething?
I know the code is quite abstracted, but I can't show all the code, and its probably too much for stackoverflow.
The main point is, that I can just import the getter and mock it like this:
import {getSomething} from "...";
getSomething = jest.fn(() => "stuff);
//Or this:
store.getters.getSomething = jest.fn(() => "stuff);
I found this stackoverflow question: TypeError during Jest's spyOn: Cannot set property getRequest of #<Object> which has only a getter
But as the npm package is rather big I can't just mock the whole package for the unit tests, as it provides some necessary pre-conditions. I tried genMockFromModule(), but I still need to target this specific function.
And as mentioned I can't simply import the function.
Any ideas?

Kotlin - Unresolved reference: Dagger{Name}Component

I'm learning how to use Dagger 2 and MVP architeture.
But I'm stuck in this error now:
Unresolved reference: DaggerHelloComponent
Look, this is my module:
#Module
class HelloModule {
lateinit var activityDagger: HelloActivityDagger
constructor(activityDagger: HelloActivityDagger) {
this.activityDagger = activityDagger
}
#Provides
fun providesHelloPresenter(): HelloActivityPresenterDagger = HelloActivityPresenterDagger(activityDagger)
}
and my component:
#Component(modules = [HelloModule::class])
interface HelloComponent {
fun inject(activityDagger: HelloActivityDagger)
}
So when I try to builder this component like this DaggerHelloComponent.create().inject(this) in my HelloActivityDagger shows me the error above.
Anyone know what I am doing wrong?
Cause I can see whats wrong in this code.
Oh, I already have followed this kapt things from this question Unresolved reference DaggerApplicationComponent and nothing happens
EDIT
To be more readable I`ve uploaded my project to Git. https://github.com/luangs7/DaggerMvpExample
Putting this code in the MyApplication class works for me to create the module starting off from your GitHub project - after the first failed build, kapt generates the DaggerHelloComponent class, and I can import it.
import android.app.Application
import br.com.squarebits.mvpexample.DaggerMvp.componentes.DaggerHelloComponent
import br.com.squarebits.mvpexample.DaggerMvp.componentes.HelloComponent
import br.com.squarebits.mvpexample.DaggerMvp.modules.HelloModule
class MyApplication : Application() {
val component: HelloComponent by lazy {
DaggerHelloComponent.builder()
.helloModule(HelloModule(HelloActivityDagger()))
.build()
}
}
If this is not happening at all, you should try the usual debugging steps of restarting Studio with File -> Invalidate Caches / Restart, cleaning and rebuilding your project, etc. Perhaps try pulling the GitHub repo to a new location and see if that builds for you - the code isn't the problem.

Aurelia module global configuration

I have installed toastr in my Aurelia app. I am able to import and use it in different views, but I can't figure out how to set/modify its global options.
Ideas?
The most trivial place to do that is in you application constructor. You must also have your toaster script loaded at this point. Here's how your app.js could look like:
import {Router} from 'aurelia-router';
import toastr from 'toastr';
export class App {
static inject() { return [Router]; }
constructor(router) {
toastr.options.closeButton = true;
// ... setup your routing etc
}
}
I assume you already have your toaster script loaded at this point. You can also move toastr initialization to any other Aurelia constructor, or any other place, I don't see any technical restrictions.