Comments (10)
@hackingbeauty thanks for quick responses - this was pretty new to me.
For anyone coming upon this in the future, here is what I did to fix this.
Per this StackOverflow question - https://stackoverflow.com/questions/47978758/how-to-exclude-node-modules-from-create-react-app-testing - I tried using shallow
instead of mount
. Didn't work.
So I pulled just AudioContext
out of this file - https://github.com/benmurden/Web-Audio-API-Mock/blob/master/AudioContext.mock.js - and added it to __mocks__/react-mic.js
per this doc - https://jestjs.io/docs/en/manual-mocks#mocking-node-modules
Tests now pass.
from react-mic.
(function() {
'use strict';
var AudioContext,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) { child[key] = parent[key]; } } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
AudioContext = (function() {
function AudioContext() {
this.destination = new AudioDestinationNode();
this.listener = new AudioListener();
}
AudioContext.prototype.activeSourceCount = 0;
AudioContext.prototype.sampleRate = 44100;
AudioContext.prototype.currentTime = 0;
AudioContext.prototype.createBuffer = function(channels, length, rate) {
return new AudioBuffer(channels, length, rate);
};
AudioContext.prototype.decodeAudioData = function() {};
AudioContext.prototype.createBufferSource = function() {
return new AudioBufferSourceNode();
};
AudioContext.prototype.createMediaElementSource = function(mediaElement) {
return new MediaElementAudioSourceNode(mediaElement);
};
AudioContext.prototype.createMediaStreamSource = function() {
return new MediaStreamAudioSourceNode();
};
AudioContext.prototype.createOscillator = function() {
return new OscillatorNode();
};
AudioContext.prototype.createScriptProcessor = function(bufferSize) {
return new ScriptProcessorNode(bufferSize);
};
AudioContext.prototype.createAnalyser = function() {
return new AnalyserNode();
};
AudioContext.prototype.createGain = function() {
return new GainNode();
};
AudioContext.prototype.createDelay = function() {
return new DelayNode();
};
AudioContext.prototype.createBiquadFilter = function() {
return new BiquadFilterNode();
};
AudioContext.prototype.createWaveShaper = function() {
return new WaveShaperNode();
};
AudioContext.prototype.createPanner = function() {
return new PannerNode();
};
AudioContext.prototype.createConvolver = function() {
return new ConvolverNode();
};
AudioContext.prototype.createChannelSplitter = function() {
return new ChannelSplitterNode();
};
AudioContext.prototype.createChannelMerger = function() {
return new ChannelMergerNode();
};
AudioContext.prototype.createDynamicsCompressor = function() {
return new DynamicsCompressorNode();
};
AudioContext.prototype.createWaveTable = function() {
throw new Error("createWaveTable is obsolete. Use createPeriodicWave instead.");
};
AudioContext.prototype.createPeriodicWave = function() {
return new PeriodicWave();
};
AudioContext.prototype.createJavaScriptNode = function(bufferSize) {
return new JavaScriptNode(bufferSize);
};
AudioContext.prototype.createGainNode = function() {
return this.createGain();
};
AudioContext.prototype.createDelayNode = function() {
return this.createDelay();
};
return AudioContext;
})();
window.AudioContext = AudioContext;
})();
from react-mic.
Hey @jbschrades where did you exactly put this file? I can't get it to work in my CRA app 😕
from react-mic.
OK, can you fix it and issue a PR? What is your test suite?
from react-mic.
Using jest with create-react-app. I can't get it to work and what is there looks correct. Maybe the problem is with jest?
from react-mic.
from react-mic.
It's just a basic integration test to check if the app renders. Failing on the import statement in a component down in the tree.
import { ReactMic } from "react-mic"
I'm not testing it directly.
from react-mic.
from react-mic.
mocks/react-mic.js
I got stuck with same issue. Can you expose this react-mic.js
file? I didn't quite get how you pulled AudioContext
out of this file - https://github.com/benmurden/Web-Audio-API-Mock/blob/master/AudioContext.mock.js
from react-mic.
(function() { 'use strict'; var AudioContext, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) { child[key] = parent[key]; } } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; AudioContext = (function() { function AudioContext() { this.destination = new AudioDestinationNode(); this.listener = new AudioListener(); } AudioContext.prototype.activeSourceCount = 0; AudioContext.prototype.sampleRate = 44100; AudioContext.prototype.currentTime = 0; AudioContext.prototype.createBuffer = function(channels, length, rate) { return new AudioBuffer(channels, length, rate); }; AudioContext.prototype.decodeAudioData = function() {}; AudioContext.prototype.createBufferSource = function() { return new AudioBufferSourceNode(); }; AudioContext.prototype.createMediaElementSource = function(mediaElement) { return new MediaElementAudioSourceNode(mediaElement); }; AudioContext.prototype.createMediaStreamSource = function() { return new MediaStreamAudioSourceNode(); }; AudioContext.prototype.createOscillator = function() { return new OscillatorNode(); }; AudioContext.prototype.createScriptProcessor = function(bufferSize) { return new ScriptProcessorNode(bufferSize); }; AudioContext.prototype.createAnalyser = function() { return new AnalyserNode(); }; AudioContext.prototype.createGain = function() { return new GainNode(); }; AudioContext.prototype.createDelay = function() { return new DelayNode(); }; AudioContext.prototype.createBiquadFilter = function() { return new BiquadFilterNode(); }; AudioContext.prototype.createWaveShaper = function() { return new WaveShaperNode(); }; AudioContext.prototype.createPanner = function() { return new PannerNode(); }; AudioContext.prototype.createConvolver = function() { return new ConvolverNode(); }; AudioContext.prototype.createChannelSplitter = function() { return new ChannelSplitterNode(); }; AudioContext.prototype.createChannelMerger = function() { return new ChannelMergerNode(); }; AudioContext.prototype.createDynamicsCompressor = function() { return new DynamicsCompressorNode(); }; AudioContext.prototype.createWaveTable = function() { throw new Error("createWaveTable is obsolete. Use createPeriodicWave instead."); }; AudioContext.prototype.createPeriodicWave = function() { return new PeriodicWave(); }; AudioContext.prototype.createJavaScriptNode = function(bufferSize) { return new JavaScriptNode(bufferSize); }; AudioContext.prototype.createGainNode = function() { return this.createGain(); }; AudioContext.prototype.createDelayNode = function() { return this.createDelay(); }; return AudioContext; })(); window.AudioContext = AudioContext; })();
That did not work for me, I am still getting the same error. What is your Node and npm version?
from react-mic.
Related Issues (20)
- Is there any option to Pause the Recording ? HOT 1
- window is undefined HOT 3
- What is the default sample rate in Heartz that it records in? HOT 1
- Unable to set channelCount to 1
- onStop callback not refreshed on componentUpdate HOT 4
- Can't listen to file after downloading to PC
- onStop returns an Object, So how to get Blob that contains Blob data.
- Blobs received in onData function are unusable
- facing type error while testing 'npm run test' in reactjs
- Good morning. I am using react-mic. While using it, I found something strange on window pc, mac pc, and mobile.
- Not working correctly in deployment env HOT 2
- React Mic Gold Website Not Working HOT 8
- How can i upload this blob to firebase storage HOT 2
- Find Frequency from Blobs?
- How to use with typescript project (like NextJs) ? HOT 1
- add a megaphone feature? pls?
- Mic detection
- Doesn't support in react 18.0.x
- Browser audio recording is not supported HOT 2
- How well supported is this package? Is it worth using today?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-mic.