I created test-file in client folder test.spec.ts:
describe('Test coordinates method', () => {
beforeEach(() => {
});
test('You should have equal values', () => {
const a = Meteor.call('sumCoords',34,45);
expect(a).toBe(79);
});
Then I’m starting this test and get error
ReferenceError: Meteor is not defined
22 |
23 |
> 24 | const a = Meteor.call('sumCoords',34,45);
25 | expect(a).toBe(79);
26 | });
27 |
at client/imports/app/shared/location.spec.ts:24:11
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:388:26)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/dist/proxy.js:79:39)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:387:32)
at Zone.Object.<anonymous>.Zone.run (node_modules/zone.js/dist/zone.js:138:43)
at Object.testBody.length (node_modules/jest-zone-patch/index.js:50:27)
Another tests are working and showing “PASS” in terminal.
I use Meteor method in another files and it works correctly.
I found some answer in Google and tried to add import { Meteor } from 'meteor/meteor'; but get the same test-fail with error Cannot find module 'meteor/meteor' from 'location.spec.ts'
Meteor.call from the client does not return a result like that. It has an asynchronous callback.
On the client, if you do not pass a callback and you are not inside a stub, call will return undefined , and you will have no way to get the return value of the method. That is because the client doesn’t have fibers, so there is not actually any way it can block on the remote execution of a method.
Meteor.call('sumCoords',34,45, (err, a) => {
expect(a).toBe(79);
})
However, you’ll need to ensure this is an asynchronous test. You may also have syntax like expect(a).to.eventually.equal(79) which your test framework may support.