問題タブ [chai-as-promised]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - Electron、Spectron: 別の JavaScript ファイルにテスト ケースを記述する方法
私は電子アプリケーションをテストしていますこれらのテクノロジ、Spectron、Chai、chai を使用して、テストケースを別のファイルに書きたいと約束しましたが、すべてを 1 つのファイルにまとめました。
これが私が試したことです、
単に、テスト初期化ファイルから、ケース 1 とケース 2 を別のファイルに書きたいだけです。
promise - API テストにタイムアウトを使用する代わりに、より良いソリューションとして Promise を使用していますか - mocha
mocha/chai を使用した API テストでタイムアウトを使用する代わりに、Promiseを使用することはより良い解決策ですか? 多くのテストで以下のようなエラーが発生しており、これらのエラーを防止したいと考えています。Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
javascript - Sinon, observing different behaviour using Promise.reject() to stub.rejects()
I was having issues running a test (in Node),
I was simulating a promise being rejected, and my code should retry (using promise-retry if that could be relevant).
When I simulated the rejected promise using stub.returns(Promise.reject(error)
I was getting a uncaught error warnings (for my dummyErrors
), even though I am catching errors where I call my function...
-note, these uncaught errors were only happening in the unit tests not in real calls.
I discovered that by changing to use the stub.rejects()
syntax:
I no longer get the uncaught error warnings.
My issue is solved, however I would like to get a better understand as to why, I looked at the sinon source code and it looks like the implementation of .rejects
is no different
node.js - nodejs/mocha/chai as promise : 外部で初期化される予想される非同期関数で使用される変数
私はモカ/チャイが初めてで、次の問題を解決するために2日間費やしましたが、成功しませんでした(以下のコードは概念を提示するためのものであり、実際のものではないことに注意してください)。
「api.js」と呼ばれる JS ファイルを取得しました。このファイルでは、SERVER_URL などの変数が dotenv フレームワークを介してファイルの先頭で初期化されています。
api.js:
これで、次の「test.js」ファイルを取得できました。
test.js:
問題は、テスト中に SERVER_URL が定義されておらず、(私は所有者ではないため) api.js を変更できず、test.js だけを変更できることです。
SERVER_URL 変数を正しく設定して (api.js の process.env.SERVER_URL 値に) テストを実行するにはどうすればよいですか?
リファクタリングなしで解決策はありますか?
そうでない場合、最善の解決策は何ですか?
専門家の皆様、貴重なご協力に感謝いたします