using the server variable in ember-cli-mirage tests - ember-cli-mirage

I'm trying to use ember-cli-mirage in my tests but running into problems. I'm using ember and ember-data 2.1.0 so that may have something to do with this.
I'm able to use mirage in development just fine. I've defined factories, routes, scenarios, etc with no problem.
The problem is when i attempt to create models in tests. The test below errors out:
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'frontend/tests/helpers/start-app';
let application;
module('Acceptance | Customer', {
beforeEach() {
application = startApp();
},
afterEach() {
Ember.run(application, 'destroy');
}
});
test('viewing customers', function(assert) {
server.createList('customer', 2);
visit('/admin/customers');
andThen(() => assert.equal(find('#customers-table tbody tr').length, 2));
});
This results in:
not ok 1 PhantomJS 1.9 - Acceptance | Customer: viewing customers
---
actual: >
null
message: >
Died on test #1 at http://localhost:7357/assets/test-support.js:3124
at http://localhost:7357/assets/frontend.js:2434
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:6846: 'undefined' is not a function (evaluating 'newCollection[method].bind(newCollection)')
Log: |
...
Should I be bootstrapping mirage somewhere?

This is actually caused by Phantom 1.9 not having bind (you can see in the error message, undefined refers to bind).
If you view the other notes section of the Installation docs you'll see you can get around this by installing ember-cli-es5-shim (or upgrading to PhantomJS 2.0).

Related

CableReady (Rails) Basic case giving mystifying error message

cable_ready 4.5.0
rails 6.1.4.1
ruby 3.0.2p107
This is a simple example from the basic tutorial (https://www.youtube.com/watch?v=F5hA79vKE_E) I suspect the error I am getting is because either cable_ready or rails evolved a little and created a tiny incompatibility.
I get this error in the JS console:
It is triggered when in my controller I ask cable ready to:
cable_ready["timeline"].console_log(message: "***** cable ready post created")
Which leads to my timeline_channel to:
received(data) {
console.log("******** Received data:", data.operations)
if (data.cableReady) CableReady.perform(data.operations)
}
My interpretation is perform causes this line in cable_ready.js line 13:
operations.forEach(function (operation) {
if (!!operation.batch) batches[operation.batch] = batches[operation.batch] ? ++batches[operation.batch] : 1;
});
Is finding something in the received data that it doesn't like.
That's where my trail ends. Can someone see what I am doing wrong, or tell me what other code you'd like me to include?
Solution: downgrade the version of the cable_ready javascript library.
I previously (maybe a year ago) did this tutorial using CableReady 4.5, Ruby 2.6.5 and Rails 6.0.4 and it worked like a charm back then as well as today.
But today, I tried this tutorial again on a duplicate project--same versions of CR, Ruby, and Rails and now I get java console errors similar to yours.
TypeError: undefined is not a function (near '...operations.forEach...')
perform -- cable_ready.js:13
received -- progress_bar_channel.js:8
I looked at the output of yarn list and saw that cable_ready was version 5.0.0-pre8 on the bad project and it was 5.0.0-pre1 on the good project. The downgrade could be accomplished with yarn add cable_ready#^5.0.0-pre1 in the bad project folder and now both projects work.
FYI for other newbies like me trying to understand how CableReady works: This tutorial gives another example of CableReady, and was also fixed the same way.

TypeError: expect(...).toBeObservable is not a function - Jasmine marbles

I am trying to write a basic ngrx effects testing. However I keep getting the error as TypeError: expect(...).toBeObservable is not a function.
This is a new project setup with Angular 7. I had no issues with my previous projects which ran in angular 4.
Initially thought it could be something to do with packages so upgraded all packages to the most latest but no luck yet.
I event tried to test a very simple observable as expect(effects.test$).toBeObservable(5); but it gives the same error. As mentioned in the title I am using jasmine-marbles and the version is 0.4.1.
You need to init the test scheduler and add matchers in before each or toBeObservable will not be defined:
import { addMatchers, initTestScheduler } from 'jasmine-marbles';
beforeEach(() => {
...
initTestScheduler();
addMatchers();
});

How to resolve error 'this.fs.stat is not a function' when using LokiJS and Angular?

I'm getting the error ('this.fs.stat is not a function') on line 2256 of lokijs.js. Environment is Electron with Angular 5.x and LokiJS v1.5.3.
fs is set up on line 2244 of lokijs.js (this.fs = require('fs');) but when I examine this.fs in the browser tools immediately after that line executes, it is just an empty object.
I've been beating my head against LokiJS all afternoon and have managed to get this far, but have no idea where to go from here. fs has been in node since forever, so I don't think it's an issue with a node version.
I'm aware of the issues with require and webpack, but since this is happening in LokiJS, I'm not sure whether this is related and if so what the proper fix would be.
Any ideas/suggestions?
Thanks.
Update #1
Code:
import * as Loki from 'lokijs';
import { LokiFsAdapter } from 'lokijs';
this.adapter = new LokiFsAdapter();
this.db = new Loki('my.db', {
env: 'NODEJS',
autoload: true,
autosave: true,
verbose: true,
autoloadCallback: this.initCollections
});
This gets me the error I mentioned above. If I switch the first line to import { Loki } from 'lokijs'; I get this error instead: Uncaught (in promise): TypeError: lokijs_1.Loki is not a constructor

WebStorm 11 EAP - Dart Unit Test Throwing Errors

I've been using the Guinness test framework for some functional testing in my Dart library.
I think one of the new updates to either WebStorm or Dart SDK broke.
I have the following:
import 'package:guinness/guinness.dart';
import 'package:tickets/shared/schemas.dart';
import 'package:tickets/db/seeder.dart';
import 'package:tickets/db/db_config.dart';
import '../bin/mongo_model.dart';
main() {
DbConfigValues config = new DbConfigValues();
MongoModel model = new MongoModel(config.testDbName, config.testDbURI, config.testDbSize);
//A Test DTO
RouteDTO routeDTO = new RouteDTO()..duration=120..price1=90.00..price2=91.00..price3=95.00..seats=7;
describe("The Ticket MongoModel", () {
it("should create a record DTO and write to the db", () {
var originalID = routeDTO.id;
return model.createByItem(routeDTO).then(( var dto ) {
expect(originalID).toBeNull();
expect(routeDTO.id).toBeNotNull();
expect(dto.id).toEqual(routeDTO.id);
});
});
});
}
Which results in:
/usr/local/opt/dart/libexec/bin/dart --ignore-unrecognized-flags --checked --enable-vm-service:52158 --trace_service_pause_events /private/var/folders/br/4n3vt5lj0qq11xk0fdmjk9y80000gn/T/jetbrains_unit_config.dart
Testing started at 3:31 PM ...
Unhandled exception:
Could not resolve a package location for base at file:///private/var/folders/br/4n3vt5lj0qq11xk0fdmjk9y80000gn/T/jetbrains_unit_config.dart
#0 _handlePackagesReply (dart:_builtin:416)
#1 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
Observatory listening on http://127.0.0.1:52158
Process finished with exit code 255
Question: How do i get guiness working with WebStorm in 11EAP.
I suggest to run the test as a standard command line Dart application. You can create corresponding run configuration manually (Run | Edit Configurations | [+] | Dart Command Line App), or remove current DartUnit run configuraton (Run | Edit Configurations) and then right click the main file. You won't get test result tree this way, but you'll see test results in the IDE console.
According to Alexanders answer I found a solution for me - I'm using the bash plugin for this...

Angular in Rails throws an error in production `Error: [$injector:unpr] Unknown provider: e`

When running my app in development it works fine. but when deployed, it throws this error :
Error: [$injector:unpr] Unknown provider: e
The url to the app : http://shimizu.leafycode.com/panel/signin
The js files : https://gist.github.com/THPubs/3a9e088ad3410e18030c
I followed other stack-overflow answers and fixed my app accordingly but still the problem is there! Please help.
Your code is being minified and I can see at least one place in app.js where you are not using the array notation when calling .config and .run
So in your app.js update the line
.config(function($mdThemingProvider) {
to
.config(['$mdThemingProvider', function($mdThemingProvider) {
// ... Your code ...
}])
and the line
.run(function($rootScope, $templateCache) {
to
.run(['$rootScope', '$templateCache', function($rootScope, $templateCache) {
// .. Your code ...
}])
Double check other places in your code that you are injecting services.

Resources