TypeError: has no method 'async' - intern

I'm trying to run the Async example and have the following code:
registerSuite({
name: 'Test Dashboard empty after removing all projects and data',
setup: function () {
var dfd = this.async(1000);
console.info('\n In setup');
remote = this.remote;
remote.setWindowSize(1024,768);
When I run this, I'm seeing the following error:
TypeError: Object #<Suite> has no method 'async'
at Suite.registerSuite.setup <tests/dashboard/dashboard_empty.js:18:28>
at <Suite.target.(anonymous function).dispatcher [as setup] (/home/bkuhlman/internjs_func/Lopez-Internjs-Func/node_modules/intern/node_modules/dojo/aspect.js:95:31)>
at callOnSuite <node_modules/intern/lib/Suite.js:157:42>
at call <node_modules/intern/lib/Suite.js:208:13>
at Suite.run <node_modules/intern/lib/Suite.js:306:4>
at <node_modules/intern/lib/Suite.js:237:13>
at signalListener <node_modules/intern/node_modules/dojo/Deferred.js:37:21>
at Promise.then.promise.then <node_modules/intern/node_modules/dojo/Deferred.js:258:5>
at runTest <node_modules/intern/lib/Suite.js:236:46>
at <node_modules/intern/lib/Suite.js:249:7>
What am I missing?
Thanks,
Brad

It is as the error describes. setup is a suite lifecycle method, not a test method, so it has no this.async. If you need to perform an asynchronous operation from a lifecycle method you will need to return a promise. This will be addressed in a future version of Intern.

Related

Before test runs, fails on CCI pipeline: "TypeError: Cannot read property 'createEvent' of null"

I have tried researching other topics similar to this error message ( such as from here, here, here among others. ):
TypeError: Cannot read property 'createEvent' of null
In our test suit we have a lot of mocked network calls as a single mocking layer, but there is a throw new Error('unexpected URL') handler for missing calls.
Also, I have verified all of my ReactTesting findBy queries are correctly declared with async/await syntax. Sometimes the tests work, othertimes fails.
What is really curious, is the error happens ONLY in Circle CI before any tests run, it appears, based on the error message call stack:
#!/bin/bash -eo pipefail
yarn test:ci
yarn run v1.22.11
$ jest --ci --runInBand
/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905
var evt = document.createEvent('Event');
^
TypeError: Cannot read property 'createEvent' of null
at Object.invokeGuardedCallbackDev (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:3905:26)
at invokeGuardedCallback (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
at flushPassiveEffectsImpl (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23543:11)
at unstable_runWithPriority (/home/circleci/project/node_modules/react-dom/node_modules/scheduler/cjs/scheduler.development.js:468:12)
at runWithPriority$1 (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
at flushPassiveEffects (/home/circleci/project/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
at Object.<anonymous>.flushWork (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
at Immediate.<anonymous> (/home/circleci/project/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1003:11)
at processImmediate (internal/timers.js:464:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
I have not seen this error locally, even when running the same command as my Circle CI command.
Any ideas about this, other than unhandled
Can you try this. async() await and use expect() function and also catch the execption by new Error Object.
it("Should ...", async () => {
await myFn(async () => {
// some operations
expect(await element.length).toBe(10).toThrow(new Error("something went wrong!"))
});
});
Try adding expect(something...) to the tests, like mentioned here.
You should finish your test with some sort of an assertion.

Shopify React Next Cannot read property "/_app" of undefined

I am trying to setup an environment to develop a shopify theme, and I followed the tutorial found here:
https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/build-your-user-interface-with-polaris
But when I connected my server, the app, the store and so on, when I started integrating polaris, on build I started getting errors.
First I had an error about a missing module build-manifest.json and I found a suggestion somewhere on the forums to make a blank file with just {} in it in the .next/ directory and so I did.
Then it complained about react-loadable-manifest.json missing, and I did the same for it.
Both of these errors were being thrown from this piece of code:
server.use(async (ctx) => {
await handle(ctx.req, ctx.res); // <-- this line
ctx.respond = false;
ctx.res.statusCode = 200;
return;
});
And now I have the following errors:
error - ./node_modules/#shopify/polaris/dist/styles.css
TypeError: Cannot read property 'tapAsync' of undefined
TypeError: Cannot read property '/_app' of undefined
Thats the full stack, I dont see any "custom" code related to it:
error - ./node_modules/#shopify/polaris/dist/styles.css
TypeError: Cannot read property 'tapAsync' of undefined
TypeError: Cannot read property '/_app' of undefined
at getPageFiles (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\get-page-files.js:1:311)
at getDocumentFiles (C:\Users\Darkbound\Desktop\shopifyreact\server\.next\server\pages\_document.js:266:54)
at Head.render (C:\Users\Darkbound\Desktop\shopifyreact\server\.next\server\pages\_document.js:589:19)
at processChild (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3450:18)
at resolve (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3270:5)
at ReactDOMServerRenderer.render (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3753:22)
at ReactDOMServerRenderer.read (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:3690:29)
at renderToStaticMarkup (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\react-dom\cjs\react-dom-server.node.development.js:4314:27)
at renderDocument (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\render.js:3:715)
at renderToHTML (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\render.js:56:103)
at async C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:107:97
at async C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:100:142
at async DevServer.renderToHTMLWithComponents (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:132:387)
at async DevServer.renderErrorToHTML (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:134:327)
at async DevServer.render (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:72:236)
at async Object.fn (C:\Users\Darkbound\Desktop\shopifyreact\server\node_modules\next\dist\next-server\server\next-server.js:56:580)
I came across this issue when jumping next multiple dependencies versions at once. I was able to resolve it by removing the wrapped Container
https://github.com/vercel/next.js/blob/master/errors/app-container-deprecated.md

TypeError: Connot read property 'render' of undefiend while testing a js on node js using mocha and chai

I am doing some testing on my js function and it is my first time doing this and I am getting an error of:
TypeError: Cannot read property 'render' of undefined
I am using chai and mocha. Here is my test code
test1.test.js
it('should return all the data based on the given appname' , function () {
assert.isArray(acc.fetchData().getKeys());
})
This is what on my js function:
exports.fetchData = function (req, res) {
'use strict';
res.render('pages/test1', {
test: a.getKeys(),
arrayToPull: rootValueCombination
});
};
I tried using supertest but I have no luck. I used istanbul as a code coverage which is a bit odd as i am getting 100% but I am getting failed on mocha test.
You are not passing a parameter to fetchData
assert.isArray(acc.fetchData().getKeys());
and res is the second parameter of the function. You need to pass the correct variable to the function, the one which has a render function.

Should js Cannot read property 'should' of null

i try to use the testing tool mocha in node. Consider the following test scenario
var requirejs = require('requirejs');
requirejs.config({
//Pass the top-level main.js/index.js require
//function to requirejs so that node modules
//are loaded relative to the top-level JS file.
nodeRequire: require
});
describe('Testing controller', function () {
it('Should be pass', function (done) {
(4).should.equal(4);
done();
});
it('Should avoid name king', function (done) {
requirejs(['../server/libs/validate_name'], function (validateName) {
var err_test, accountExists_test, notAllow_test, available_test;
validateName('anu', function (err, accountExists, notAllow, available) {
accountExists.should.not.be.true;
done();
});
});
});
});
as a testing result i have got:
$ make test
./node_modules/.bin/mocha \
--reporter list
. Testing controller Should be pass: 0ms
1) Testing controller Should avoid name anu
1 passing (560 ms)
1 failing
1) Testing controller Should avoid name anu:
Uncaught TypeError: Cannot read property 'should' of null
at d:\townspeech\test\test.spec.js:23:30
at d:\townspeech\server\libs\validate_name.js:31:20
at d:\townspeech\test\test.spec.js:22:13
at Object.context.execCb (d:\townspeech\node_modules\requirejs\bin\r.js:1869:33)
at Object.Module.check (d:\townspeech\node_modules\requirejs\bin\r.js:1105:51)
at Object.Module.enable (d:\townspeech\node_modules\requirejs\bin\r.js:1376:22)
at Object.Module.init (d:\townspeech\node_modules\requirejs\bin\r.js:1013:26)
at null._onTimeout (d:\townspeech\node_modules\requirejs\bin\r.js:1646:36)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
make: *** [test] Error 1
The first pass without any complication but the second, it seems like, that could not attach module shouldjs. Why?
I had the same problem. I solved it by using:
(err === null).should.be.true;
You can use should directly
should.not.exist(err);
That's a known problem with the should library: As it extends object, of course it only works when you have a concrete object. As null, by definition, means that you don't have an object, you can not call any methods on it or access any of its properties.
Hence, should is not available in this case.
Basically, you have two options of how to deal with this:
You could exchange actual and expected. This way, as long as you do not expect null, you have an object in the beginning and hence can access its should property. But, this is not nice, as it changes semantics, and does not work in all cases.
You could exchange the should library by another assertion library that does not have this problem.
Personally, I'd go with option 2, and my highly subjective personal favorite for this is node-assertthat (which has been written by me, hence it's my favorite).
Anyway, there are lots of other options, such as expect. Feel free to use any of these assertion libraries that best suits your style of writing tests.
One more option that I don't see mentioned here:
should(err === null).be.null
In you example that would would be:
should(accountExists).be.null
I always find expect works better with null and undefined as follows:
expect(err).be.null

Node-Webkit with external module containing native code

I'm using node-webkit with an external module called edge.
According to the node-webkit docs modules that contain native code must be recompiled using nw-gyp as oppose to node-gyp. I was able to recompile without error and node-webkit seems to import the module OK.
Heres my code. The code I'm trying to use:
var edge = require('edge.node');
var hello = edge.func(function () {/*
async (input) =>
{
return ".NET welcomes " + input.ToString();
}
*/});
hello('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});
Which throws the following error when run within node-webkit.
Uncaught TypeError: Object [object Object] has no method 'func'
If write the object out to console.log I can see:
Object {initializeClrFunc: function}
initializeClrFunc: function () { [native code] }
__proto__: Object
So the module seems to have loaded. If I run the same code outside of node-webkit, everything works perfectly and I can access the func function. This is driving me crazy - and any help would be really appreciated.
func method is provided by edge.js, the wrapper around edge.node native module. So you should replace require('edge.node') by require('edge').

Resources