A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
test: search-vides /api/videos request
Christian Fei45a1c1740142
diff --git a/client/test/search-videos.test.js b/client/test/search-videos.test.jsnew file mode 100644index 0000000..20f0b4d--- /dev/null+++ b/client/test/search-videos.test.js@@ -0,0 +1,24 @@+/* global describe, it */+import sinon from 'sinon'+import { fixture, html, assert } from '@open-wc/testing'++import '../components/search-videos.js'++describe('search-videos', () => {+ it('makes HTTP request to API with search term', async () => {+ const el = await fixture(html`+ <search-videos></search-videos>+ `)++ const fetchStub = sinon.stub(window, 'fetch')+ window.fetch.resolves({ json: () => Promise.resolve([]) })++ const $search = el.querySelector('[type="search"]')++ $search.value = 'test'+ $search.dispatchEvent(new Event('input'))++ assert.equal(fetchStub.callCount, 1)+ assert.equal(fetchStub.args[0][0], '/api/videos?filter=test')+ })+})diff --git a/package-lock.json b/package-lock.jsonindex 9de3baf..3540fde 100644--- a/package-lock.json+++ b/package-lock.json@@ -14,6 +14,7 @@"devDependencies": {"@open-wc/testing": "^3.0.0-next.5","@web/test-runner": "^0.20.2",+ "sinon": "^20.0.0","standard": "^17.1.2","undici": "^7.9.0"}@@ -876,6 +877,48 @@"dev": true,"license": "MIT"},+ "node_modules/@sinonjs/commons": {+ "version": "3.0.1",+ "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz",+ "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==",+ "dev": true,+ "license": "BSD-3-Clause",+ "dependencies": {+ "type-detect": "4.0.8"+ }+ },+ "node_modules/@sinonjs/fake-timers": {+ "version": "13.0.5",+ "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz",+ "integrity": "sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==",+ "dev": true,+ "license": "BSD-3-Clause",+ "dependencies": {+ "@sinonjs/commons": "^3.0.1"+ }+ },+ "node_modules/@sinonjs/samsam": {+ "version": "8.0.2",+ "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.2.tgz",+ "integrity": "sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw==",+ "dev": true,+ "license": "BSD-3-Clause",+ "dependencies": {+ "@sinonjs/commons": "^3.0.1",+ "lodash.get": "^4.4.2",+ "type-detect": "^4.1.0"+ }+ },+ "node_modules/@sinonjs/samsam/node_modules/type-detect": {+ "version": "4.1.0",+ "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz",+ "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=4"+ }+ },"node_modules/@tootallnate/quickjs-emscripten": {"version": "0.23.0","resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz",@@ -5328,6 +5371,14 @@"dev": true,"license": "MIT"},+ "node_modules/lodash.get": {+ "version": "4.4.2",+ "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",+ "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==",+ "deprecated": "This package is deprecated. Use the optional chaining (?.) operator instead.",+ "dev": true,+ "license": "MIT"+ },"node_modules/lodash.merge": {"version": "4.6.2","resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",@@ -6948,6 +6999,34 @@"dev": true,"license": "ISC"},+ "node_modules/sinon": {+ "version": "20.0.0",+ "resolved": "https://registry.npmjs.org/sinon/-/sinon-20.0.0.tgz",+ "integrity": "sha512-+FXOAbdnj94AQIxH0w1v8gzNxkawVvNqE3jUzRLptR71Oykeu2RrQXXl/VQjKay+Qnh73fDt/oDfMo6xMeDQbQ==",+ "dev": true,+ "license": "BSD-3-Clause",+ "dependencies": {+ "@sinonjs/commons": "^3.0.1",+ "@sinonjs/fake-timers": "^13.0.5",+ "@sinonjs/samsam": "^8.0.1",+ "diff": "^7.0.0",+ "supports-color": "^7.2.0"+ },+ "funding": {+ "type": "opencollective",+ "url": "https://opencollective.com/sinon"+ }+ },+ "node_modules/sinon/node_modules/diff": {+ "version": "7.0.0",+ "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz",+ "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==",+ "dev": true,+ "license": "BSD-3-Clause",+ "engines": {+ "node": ">=0.3.1"+ }+ },"node_modules/slash": {"version": "3.0.0","resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",@@ -7458,6 +7537,16 @@"node": ">= 0.8.0"}},+ "node_modules/type-detect": {+ "version": "4.0.8",+ "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",+ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=4"+ }+ },"node_modules/type-fest": {"version": "0.20.2","resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz",diff --git a/package.json b/package.jsonindex f1824d7..bf3d684 100644--- a/package.json+++ b/package.json@@ -19,6 +19,7 @@"devDependencies": {"@open-wc/testing": "^3.0.0-next.5","@web/test-runner": "^0.20.2",+ "sinon": "^20.0.0","standard": "^17.1.2","undici": "^7.9.0"}