ng2-dragula
ng2-dragula copied to clipboard
don't crash angular when source model is not defined
When I drag an item between to scroll lists a couple of times and drop it in between them, I get sourceModel is undefined. This workaround fixes the issue. Perhaps this stems from a bigger issue?
Codecov Report
Merging #883 into master will decrease coverage by
0.27%. The diff coverage is0%.
@@ Coverage Diff @@
## master #883 +/- ##
==========================================
- Coverage 84% 83.72% -0.28%
==========================================
Files 8 8
Lines 300 301 +1
Branches 38 39 +1
==========================================
Hits 252 252
Misses 31 31
- Partials 17 18 +1
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...ules/ng2-dragula/src/components/dragula.service.ts | 80% <0%> (-0.71%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 808d33c...014eb3c. Read the comment docs.
Sure, there could be more checks, in which case you wouldn't put them in just one branch of the if.
But are you sure you're not just passing in a null model? Can you provide a minimal repro? There is a test suite for the code that puts models where they are meant to be. Can you write a test that fails?
It's pretty hard to write a test that fails since it's a drag between interaction of the columns. I'd have to log out and mock the inputs in the listener. When I have a chance, I'll definitely do that.
Maybe start with a stackblitz (there's a link in the bug report issue template).
If you wanted to test for it, then the existing ones for DragulaService are decent as examples. Right off the bat it might be worth putting a test for 'should do nothing if either model is null' in there!
It would be quite similar to this one
https://github.com/valor-software/ng2-dragula/blob/master/modules/ng2-dragula/src/spec/dragula.service.spec.ts#L172-L197
I should also be clear that if either model is null, then that's pretty likely to be a bug in your own code, and silently exiting in the lib is just going to make that bug harder to find.